awslabs / awslabs/agentcore-samples

gateway IAM role trust policy uses profile default region instead of --region argument

Open
#1,035 0 comments 0 reactions 1 assignee Claimed by @EashanKaushik View on GitHub
02-use-cases bug
Dominant language
Python
Stars
3.4k
Forks
1.3k
Avg merge
1d 22h
Merged PRs (30d)
30

Description

list the sample in which the bug is present.

01-tutorials/02-AgentCore-gateway/04-integration/02-runtime-gateway-mcp-toolkit/agentcore_toolkit/utils.py

Bug Description

The create_agentcore_gateway_role() function in utils.py derives the AWS region
from the default boto3 session (Session().region_name) instead of using the
--region argument passed to the toolkit. This causes the IAM role trust policy's
ArnLike condition to contain the wrong region.

For example, when deploying with --region us-east-1 but the AWS profile defaults
to eu-west-1, the trust policy is created with:

"aws:SourceArn": "arn:aws:bedrock-agentcore:eu-west-1::*"

instead of:

"aws:SourceArn": "arn:aws:bedrock-agentcore:us-east-1::*"

This prevents the AgentCore gateway service from assuming the role, causing all
tools/call requests to fail with:

"InternalServerException - Failed to obtain execution role credentials"

Note: tools/list still works because it only requires the gateway to route the
request, not assume the execution role.

The same pattern exists in create_agentcore_role() and
create_agentcore_gateway_role_s3_smithy() — all three functions should accept
a region parameter rather than deriving it from the default session.

Fix: Add a region parameter to these functions and pass self.region from the
toolkit's main.py call site.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.