Checks
Strands Version
1.9.1
Tools Package Version
0.2.3
Tools used
retrieve
Python Version
3.12.11
Operating System
macOS 15.7
Installation Method
pip
Steps to Reproduce
# This is an agent I created specifically to diagnose this problem
# Knowledge base ID is provided through the KNOWLEDGE_BASE_ID environment variable
import os
from textwrap import dedent
import boto3
from strands import Agent
from strands_tools import retrieve, use_aws
role_arn = "arn:aws:iam::XXXXXXXXXXXX:role/my-role"
sts = boto3.client("sts")
creds = sts.assume_role(RoleArn=role_arn, RoleSessionName="my-session")["Credentials"]
print(creds["AccessKeyId"])
# boto3.setup_default_session apparently doesn't work, so...
os.environ["AWS_ACCESS_KEY_ID"] = creds["AccessKeyId"]
os.environ["AWS_SECRET_ACCESS_KEY"] = creds["SecretAccessKey"]
os.environ["AWS_SESSION_TOKEN"] = creds["SessionToken"]
os.environ["AWS_DEFAULT_REGION"] = "us-west-2"
system_prompt = dedent("""\
You are an expert in solving AWS permissions issues. You will be provided with a query that will involve
a Bedrock knowledge base and possibly some AWS IAM policies. You will perform the query and if
there are any access denied errors, you will first verify the ARN of the IAM role that was used to perform
the retrieval, and then you will identify the permissions missing from that role and report them.
You will then provide the user with the additional permissions needed to successfully perform the query.
You will also provide a brief explanation of why the permissions are needed.
""")
agent = Agent(system_prompt=system_prompt, tools=[retrieve, use_aws])
response = agent("What is <system-name>?")
print("\n" + "*" * 50)
print(response.message["content"][0]["text"])
Expected Behavior
Agent should retrieve information from the knowledge base and report on it.
Actual Behavior
I'll search the knowledge base to find information about <system-name>.
Tool #1: retrieve
I encountered an error indicating that the knowledge base with the default ID doesn't exist. Let me check what knowledge bases are available in the account by listing them.
Tool #2: use_aws
Good! I can see there is a knowledge base available with the ID "<knowledge-base-id>" that contains "<system-name> documentation". Let me now try to retrieve information about <system-name> using this knowledge base ID.
Tool #3: retrieve
I'm still getting a ResourceNotFoundException even though the knowledge base appears to exist when I list them. This suggests there might be a permissions issue. Let me check the IAM role being used and verify its permissions.
Tool #4: use_aws
Now I can see that the current execution is using the IAM role `arn:aws:sts::XXXXXXXXXXXX:assumed-role/my-role/my-session`. Let me check the policies attached to this role to understand what permissions it has.
Tool #5: use_aws
Let me check what policies are attached to this role:
Tool #6: use_aws
to proceed? [y/*] y
Let me also check for any inline policies:
Tool #7: use_aws
Let me check the inline policy content:
Tool #8: use_aws
The role has the necessary permissions including `AmazonBedrockFullAccess` and a specific inline policy with `bedrock-agent-runtime:Retrieve` permissions. However, there might be an issue with the knowledge base itself. Let me get more details about the knowledge base:
Tool #9: use_aws
The knowledge base exists and is ACTIVE. The issue might be that the retrieve operation is looking for a different service endpoint or there might be a subtle permission issue. Let me try using the bedrock-agent-runtime service directly:
Tool #10: use_aws
Excellent! The direct AWS API call worked. Now I have the information about <system-name>. Based on the retrieved results, I can provide a comprehensive answer.
<answers the query with RAG results>
# note that the agent finds nothing wrong with the assumed role's permissions or with the knowledge base itself. It is able to retrieve information from the KB by querying through the use_aws tool, but not the retrieve tool.
Additional Context
This agent works when I let it use the default profile in my AWS configuration, just not when it's using the assumed role.
I have tried assuming the role and setting the environment vars before importing strands and strands_tools, but that didn't help.
Possible Solution
No response
Related Issues
No response
Checks
Strands Version
1.9.1
Tools Package Version
0.2.3
Tools used
retrieve
Python Version
3.12.11
Operating System
macOS 15.7
Installation Method
pip
Steps to Reproduce
Expected Behavior
Agent should retrieve information from the knowledge base and report on it.
Actual Behavior
Additional Context
This agent works when I let it use the default profile in my AWS configuration, just not when it's using the assumed role.
I have tried assuming the role and setting the environment vars before importing strands and strands_tools, but that didn't help.
Possible Solution
No response
Related Issues
No response