Skip to content

Commit 35afe35

Browse files
committed
Updated agentcore lambda permissions
1 parent e779567 commit 35afe35

File tree

2 files changed

+26
-46
lines changed

2 files changed

+26
-46
lines changed

src/lambda/agentcore_gateway_manager/index.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ def create_or_update_gateway(props, gateway_name):
7373
}
7474
}
7575

76-
# Create log group for gateway
77-
stack_name = props.get('StackName', 'UNKNOWN')
78-
create_log_group(gateway_name, region, stack_name)
79-
8076
# Create gateway
8177
gateway = client.create_mcp_gateway(
8278
name=gateway_name,
@@ -187,35 +183,6 @@ def delete_gateway(props, gateway_name):
187183
else:
188184
logger.info("Gateway not found")
189185

190-
# Clean up log group
191-
stack_name = props.get('StackName', 'UNKNOWN')
192-
delete_log_group(gateway_name, region, stack_name)
193186
except Exception as e:
194187
logger.error(f"Gateway deletion failed: {e}")
195188

196-
197-
def create_log_group(gateway_name, region, stack_name):
198-
"""Create CloudWatch log group for AgentCore Gateway"""
199-
log_group_name = f"{stack_name}-AgentCoreAnalyticsGateway"
200-
201-
logs_client = boto3.client('logs', region_name=region)
202-
try:
203-
logs_client.create_log_group(logGroupName=log_group_name)
204-
logger.info(f"Created log group: {log_group_name}")
205-
except logs_client.exceptions.ResourceAlreadyExistsException:
206-
logger.info(f"Log group already exists: {log_group_name}")
207-
except Exception as e:
208-
logger.warning(f"Failed to create log group: {e}")
209-
210-
211-
def delete_log_group(gateway_name, region, stack_name):
212-
"""Delete CloudWatch log group for AgentCore Gateway"""
213-
log_group_name = f"{stack_name}-AgentCoreAnalyticsGateway"
214-
logs_client = boto3.client('logs', region_name=region)
215-
try:
216-
logs_client.delete_log_group(logGroupName=log_group_name)
217-
logger.info(f"Deleted log group: {log_group_name}")
218-
except logs_client.exceptions.ResourceNotFoundException:
219-
logger.info(f"Log group already deleted: {log_group_name}")
220-
except Exception as e:
221-
logger.warning(f"Failed to delete log group: {e}")

template.yaml

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -871,11 +871,11 @@ Resources:
871871
Statement:
872872
- Effect: Allow
873873
Principal:
874-
Service: lambda.amazonaws.com
874+
Service: !Sub "lambda.${AWS::URLSuffix}"
875875
Action: sts:AssumeRole
876876
PermissionsBoundary: !If [ HasPermissionsBoundary, !Ref PermissionsBoundaryArn, !Ref "AWS::NoValue" ]
877877
ManagedPolicyArns:
878-
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
878+
- !Sub "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
879879
Policies:
880880
- PolicyName: AthenaQueryPolicy
881881
PolicyDocument:
@@ -887,7 +887,7 @@ Resources:
887887
- athena:GetQueryExecution
888888
- athena:GetQueryResults
889889
- athena:StopQueryExecution
890-
Resource: !Sub "arn:aws:athena:${AWS::Region}:${AWS::AccountId}:workgroup/primary"
890+
Resource: !Sub "arn:${AWS::Partition}:athena:${AWS::Region}:${AWS::AccountId}:workgroup/primary"
891891
- PolicyName: S3AccessPolicy
892892
PolicyDocument:
893893
Version: '2012-10-17'
@@ -925,9 +925,9 @@ Resources:
925925
- glue:GetTables
926926
- glue:GetPartitions
927927
Resource:
928-
- !Sub "arn:aws:glue:${AWS::Region}:${AWS::AccountId}:catalog"
929-
- !Sub "arn:aws:glue:${AWS::Region}:${AWS::AccountId}:database/${ReportingDatabase}"
930-
- !Sub "arn:aws:glue:${AWS::Region}:${AWS::AccountId}:table/${ReportingDatabase}/*"
928+
- !Sub "arn:${AWS::Partition}:glue:${AWS::Region}:${AWS::AccountId}:catalog"
929+
- !Sub "arn:${AWS::Partition}:glue:${AWS::Region}:${AWS::AccountId}:database/${ReportingDatabase}"
930+
- !Sub "arn:${AWS::Partition}:glue:${AWS::Region}:${AWS::AccountId}:table/${ReportingDatabase}/*"
931931
- PolicyName: KMSDecryptPolicy
932932
PolicyDocument:
933933
Version: '2012-10-17'
@@ -993,7 +993,6 @@ Resources:
993993
Runtime: python3.12
994994
MemorySize: 1024
995995
Timeout: 900
996-
Role: !GetAtt AgentCoreAnalyticsLambdaRole.Arn
997996
Environment:
998997
Variables:
999998
LOG_LEVEL: !Ref LogLevel
@@ -1064,9 +1063,26 @@ Resources:
10641063
- athena:StartQueryExecution
10651064
- athena:GetQueryExecution
10661065
- athena:GetQueryResults
1066+
- athena:StopQueryExecution
10671067
Resource:
10681068
- !Sub "arn:${AWS::Partition}:athena:${AWS::Region}:${AWS::AccountId}:workgroup/primary"
10691069
- !Sub "arn:${AWS::Partition}:athena:${AWS::Region}:${AWS::AccountId}:datacatalog/*"
1070+
- Effect: Allow
1071+
Action:
1072+
- s3:ListBucket
1073+
- s3:GetBucketLocation
1074+
- s3:GetBucketVersioning
1075+
- s3:GetObject
1076+
- s3:PutObject
1077+
- s3:DeleteObject
1078+
- s3:AbortMultipartUpload
1079+
- s3:ListMultipartUploadParts
1080+
Resource: !Sub
1081+
- "${BucketArn}/*"
1082+
- BucketArn: !If
1083+
- ShouldCreateReportingBucket
1084+
- !GetAtt ReportingBucket.Arn
1085+
- !Sub "arn:${AWS::Partition}:s3:::${ReportingBucketName}"
10701086
- Effect: Allow
10711087
Action:
10721088
- glue:GetTable
@@ -1154,6 +1170,8 @@ Resources:
11541170
- dynamodb:Query
11551171
Resource:
11561172
- !GetAtt TrackingTable.Arn
1173+
- !GetAtt ConfigurationTable.Arn
1174+
- !GetAtt AgentTable.Arn
11571175
- Effect: Allow
11581176
Action:
11591177
- cloudformation:DescribeStackResources
@@ -1171,12 +1189,6 @@ Resources:
11711189
- states:GetExecutionHistory
11721190
Resource:
11731191
- !Sub "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:execution:${AWS::StackName}*"
1174-
- Effect: Allow
1175-
Action:
1176-
- xray:GetTraceSummaries
1177-
- xray:BatchGetTraces
1178-
- xray:GetServiceGraph
1179-
Resource: "*"
11801192

11811193
##########################################################################
11821194
# AgentCore Gateway Manager Lambda Function
@@ -1260,6 +1272,7 @@ Resources:
12601272
UserPoolId: !Ref UserPool
12611273
ClientId: !Ref ExternalAppClient
12621274
ClientSecret: !GetAtt ExternalAppClient.ClientSecret
1275+
SourceCodeHash: <HASH_TOKEN>
12631276

12641277
##########################################################################
12651278
# Nested stack for selected pattern

0 commit comments

Comments
 (0)