- Newest
- Most votes
- Most comments
Hi There
I tested this myself and see the same error using the CLI.
~ $ aws bedrock-agent delete-knowledge-base --knowledge-base-id ABCDEFGH (non-existant KB ID)
An error occurred (AccessDeniedException) when calling the DeleteKnowledgeBase operation: User: arn:aws:sts::123456789012:assumed-role/*****/********* is not authorized to perform: bedrock:DeleteKnowledgeBase
Thanks for raising this, I'll go ahead and raise the issue to the Bedrock service team for further investigation
When you're trying to delete a Bedrock knowledge base using the AWS SDK for Python (Boto3) and providing an incorrectly formatted knowledge base ID, you're encountering a misleading error message about permissions rather than a validation error.
The delete_knowledge_base function in Boto3 expects a valid knowledge base ID in the correct format. When you provide an invalid format (like a knowledge base name instead of ID, or an ID with incorrect length), the API should ideally return a validation error, but instead returns an AccessDeniedException.
This appears to be an issue with how the Bedrock service handles invalid IDs. The proper way to use this function is:
def delete_knowledge_base(bedrock_agent_client, knowledge_base_id): try: bedrock_agent_client.delete_knowledge_base( knowledgeBaseId=knowledge_base_id ) logger.info("Deleted knowledge base: %s", knowledge_base_id) return True except ClientError as err: logger.error( "Couldn't delete knowledge base %s. Here's why: %s: %s", knowledge_base_id, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
To work around this issue, you should:
- Ensure you're using the correct knowledge base ID format (typically a 10-character alphanumeric string)
- Validate the ID format in your code before making the API call
- Handle the exception appropriately, recognizing that an
AccessDeniedExceptionmight actually indicate an invalid ID format rather than a permissions issue
This behavior is unexpected and could be considered a bug in how the Bedrock service handles invalid IDs.
Sources
Use DeleteKnowledgeBase with an AWS SDK - Amazon Bedrock
Use DeleteKnowledgeBase with an AWS SDK - AWS SDK Code Examples
Amazon Bedrock Agents examples using SDK for Python (Boto3) - AWS SDK Code Examples
answered a year ago
Relevant content
asked 2 years ago
asked 2 years ago
asked 2 years ago
- AWS OFFICIALUpdated 2 years ago

Thanks Matt I opened this issue with more examples if that helps: https://github.com/boto/boto3/issues/4639