Skip to content

Commit 9a800f1

Browse files
committed
Merge branch 'feature/mcp-server-2' into 'develop'
Fix MCP Gateway multi-region support by updating IAM trust policy See merge request genaiic-reusable-assets/engagement-artifacts/genaiic-idp-accelerator!452
2 parents f8e434a + cef83a8 commit 9a800f1

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/lambda/agentcore_gateway_manager/index.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def create_gateway(props, gateway_name, client):
9696
lambda_arn = props['LambdaArn']
9797
user_pool_id = props['UserPoolId']
9898
client_id = props['ClientId']
99+
execution_role_arn = props.get('ExecutionRoleArn')
99100

100101
# Create JWT authorizer config using existing Cognito resources
101102
authorizer_config = {
@@ -108,7 +109,7 @@ def create_gateway(props, gateway_name, client):
108109
# Create gateway
109110
gateway = client.create_mcp_gateway(
110111
name=gateway_name,
111-
role_arn=None,
112+
role_arn=execution_role_arn,
112113
authorizer_config=authorizer_config,
113114
enable_semantic_search=True,
114115
)

template.yaml

Lines changed: 41 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
@@ -1156,13 +1162,46 @@ Resources:
11561162
KmsKeyId: !GetAtt CustomerManagedEncryptionKey.Arn
11571163
RetentionInDays: !Ref LogRetentionDays
11581164

1165+
AgentCoreGatewayExecutionRole:
1166+
Type: AWS::IAM::Role
1167+
Condition: CreateAgentCoreLambda
1168+
Properties:
1169+
RoleName: !Sub "${AWS::StackName}-AgentCoreGatewayExecutionRole"
1170+
Description: Execution role for AgentCore Gateway
1171+
AssumeRolePolicyDocument:
1172+
Version: "2012-10-17"
1173+
Statement:
1174+
- Effect: Allow
1175+
Principal:
1176+
Service: !Sub "bedrock-agentcore.${AWS::URLSuffix}"
1177+
Action: sts:AssumeRole
1178+
Condition:
1179+
StringEquals:
1180+
aws:SourceAccount: !Ref AWS::AccountId
1181+
ArnLike:
1182+
aws:SourceArn: !Sub "arn:${AWS::Partition}:bedrock-agentcore:${AWS::Region}:${AWS::AccountId}:*"
1183+
Policies:
1184+
- PolicyName: InvokeLambdaPolicy
1185+
PolicyDocument:
1186+
Version: "2012-10-17"
1187+
Statement:
1188+
- Effect: Allow
1189+
Action: lambda:InvokeFunction
1190+
Resource: !GetAtt AgentCoreAnalyticsLambdaFunction.Arn
1191+
ManagedPolicyArns:
1192+
- !Sub "arn:${AWS::Partition}:iam::aws:policy/CloudWatchLogsFullAccess"
1193+
Tags:
1194+
- Key: Name
1195+
Value: !Sub "${AWS::StackName}-AgentCoreGatewayExecutionRole"
1196+
11591197
AgentCoreGateway:
11601198
Type: Custom::AgentCoreGateway
11611199
Condition: CreateAgentCoreLambda
11621200
DependsOn:
11631201
- AgentCoreAnalyticsLambdaFunction
11641202
- ExternalAppClient
11651203
- UserPool
1204+
- AgentCoreGatewayExecutionRole
11661205
Properties:
11671206
ServiceToken: !GetAtt AgentCoreGatewayManagerFunction.Arn
11681207
StackName: !Ref AWS::StackName
@@ -1171,6 +1210,7 @@ Resources:
11711210
UserPoolId: !Ref UserPool
11721211
ClientId: !Ref ExternalAppClient
11731212
ClientSecret: !GetAtt ExternalAppClient.ClientSecret
1213+
ExecutionRoleArn: !GetAtt AgentCoreGatewayExecutionRole.Arn
11741214
SourceCodeHash: <LAMBDA_HASH_TOKEN>
11751215

11761216
##########################################################################
@@ -5208,7 +5248,7 @@ Resources:
52085248
- profile
52095249
CallbackURLs:
52105250
- !Sub "https://${GetDomain.OutputString}.auth.${AWS::Region}.amazoncognito.com"
5211-
- "https://us-east-1.quicksight.aws.amazon.com/sn/oauthcallback"
5251+
- !Sub "https://${AWS::Region}.quicksight.aws.amazon.com/sn/oauthcallback"
52125252
- !Sub "https://${CloudFrontDistribution.DomainName}/"
52135253
LogoutURLs:
52145254
- !Sub "https://${GetDomain.OutputString}.auth.${AWS::Region}.amazoncognito.com"

0 commit comments

Comments
 (0)