Skip to content

Commit 63bbafe

Browse files
committed
Fixed agentcore gateway policy to support multi-region deployment
1 parent 49b9254 commit 63bbafe

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/lambda/agentcore_gateway_manager/index.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,38 @@ def create_gateway(props, gateway_name, client):
121121
logger.info("Waiting for IAM propagation...")
122122
time.sleep(30)
123123

124+
# Override trust policy to support all regions
125+
gateway_role_arn = gateway.get('executionRoleArn')
126+
if gateway_role_arn:
127+
role_name = gateway_role_arn.split('/')[-1]
128+
logger.info(f"Updating trust policy for role: {role_name}")
129+
130+
iam_client = boto3.client('iam')
131+
sts_client = boto3.client('sts')
132+
account_id = sts_client.get_caller_identity()['Account']
133+
134+
try:
135+
iam_client.update_assume_role_policy(
136+
RoleName=role_name,
137+
PolicyDocument=json.dumps({
138+
"Version": "2012-10-17",
139+
"Statement": [{
140+
"Effect": "Allow",
141+
"Principal": {"Service": "bedrock-agentcore.amazonaws.com"},
142+
"Action": "sts:AssumeRole",
143+
"Condition": {
144+
"StringEquals": {"aws:SourceAccount": account_id},
145+
"ArnLike": {"aws:SourceArn": f"arn:aws:bedrock-agentcore:*:{account_id}:*"}
146+
}
147+
}]
148+
})
149+
)
150+
logger.info("Trust policy updated successfully to support all regions")
151+
except Exception as e:
152+
logger.warning(f"Failed to update trust policy: {e}")
153+
else:
154+
logger.warning("Gateway executionRoleArn not found, skipping trust policy update")
155+
124156
# Add analytics Lambda target
125157
logger.info("Adding analytics Lambda target...")
126158
client.create_mcp_gateway_target(

template.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,12 @@ Resources:
11341134
- logs:CreateLogGroup
11351135
- logs:PutLogEvents
11361136
- logs:DeleteLogGroup
1137+
- logs:PutDeliverySource
1138+
- logs:DeleteDeliverySource
1139+
- logs:PutDeliveryDestination
1140+
- logs:DeleteDeliveryDestination
1141+
- logs:DescribeDeliveryDestinations
1142+
- logs:DescribeDeliverySources
11371143
- iam:PassRole
11381144
- iam:CreateRole
11391145
- iam:AttachRolePolicy
@@ -1173,6 +1179,18 @@ Resources:
11731179
ClientSecret: !GetAtt ExternalAppClient.ClientSecret
11741180
SourceCodeHash: <LAMBDA_HASH_TOKEN>
11751181

1182+
AgentCoreAnalyticsLambdaInvokePermission:
1183+
Type: AWS::Lambda::Permission
1184+
Condition: CreateAgentCoreLambda
1185+
DependsOn:
1186+
- AgentCoreGateway
1187+
- AgentCoreAnalyticsLambdaFunction
1188+
Properties:
1189+
FunctionName: !Ref AgentCoreAnalyticsLambdaFunction
1190+
Action: lambda:InvokeFunction
1191+
Principal: !Sub "bedrock-agentcore.${AWS::URLSuffix}"
1192+
SourceArn: !GetAtt AgentCoreGateway.GatewayArn
1193+
11761194
##########################################################################
11771195
# Nested stack for selected pattern
11781196
##########################################################################
@@ -5208,7 +5226,7 @@ Resources:
52085226
- profile
52095227
CallbackURLs:
52105228
- !Sub "https://${GetDomain.OutputString}.auth.${AWS::Region}.amazoncognito.com"
5211-
- "https://us-east-1.quicksight.aws.amazon.com/sn/oauthcallback"
5229+
- !Sub "https://${AWS::Region}.quicksight.aws.amazon.com/sn/oauthcallback"
52125230
- !Sub "https://${CloudFrontDistribution.DomainName}/"
52135231
LogoutURLs:
52145232
- !Sub "https://${GetDomain.OutputString}.auth.${AWS::Region}.amazoncognito.com"

0 commit comments

Comments
 (0)