@@ -36,7 +36,7 @@ Parameters:
3636 Description : Version of AWS ParallelCluster to deploy.
3737 Type : String
3838 AllowedPattern : " ^([0-9]+)\\ .([0-9]+)\\ .([0-9]+)(,([0-9]+)\\ .([0-9]+)\\ .([0-9]+))*$"
39- ConstraintDescription : Please specify a valid ParallelCluster version .
39+ ConstraintDescription : Please specify a comma separated list of valid ParallelCluster versions .
4040 ImageBuilderVpcId :
4141 Description : (Optional) Select the VPC to use for building the container images. If not selected, default VPC will be used.
4242 Type : String
@@ -240,7 +240,15 @@ Resources:
240240 import os
241241 import re
242242 import time
243-
243+
244+ def get_partition(region):
245+ if region.startswith('us-gov-'):
246+ return 'aws-us-gov'
247+ elif region.startswith('cn-'):
248+ return 'aws-cn'
249+ else:
250+ return 'aws'
251+
244252 def handler(event, context) :
245253 response_data = {}
246254 response_status = cfnresponse.SUCCESS
@@ -255,7 +263,13 @@ Resources:
255263 if event['RequestType'] in ['Create', 'Update'] :
256264 response_data["Message"] = "Resource creation successful!"
257265 cfn = boto3.client('cloudformation')
266+
267+ sts_client = boto3.client('sts')
268+ caller_identity = sts_client.get_caller_identity()
269+ account_id = caller_identity['Account']
270+
258271 result = ""
272+ api_gateway_arns = []
259273
260274 api_id = event['ResourceProperties'].get('ApiGatewayRestApiId')
261275 print(f"ApiGatewayRestApiId : {api_id}")
@@ -304,23 +318,28 @@ Resources:
304318 if output['OutputKey'] == 'ParallelClusterApiInvokeUrl' :
305319 # Construct the result string
306320 result = f"{result}{version}={output['OutputValue']},"
307- print(f"Version={version}, ApiURL={output['OutputValue']}")
321+
322+ parsed_url = urlparse(output['OutputValue']).hostname.split('.')[0]
323+ api_gateway_arns.append(f"arn:{get_partition(os.environ['AWS_REGION'])}:execute-api:{os.environ['AWS_REGION']}:{account_id}/{parsed_url}/*/*")
324+ print(f"API arn : {parsed_url}")
325+
326+ print(f"Version={version}, ApiURL={output['OutputValue']}, ")
308327 break
309328
310329 except Exception as e :
311330 print(f"Error processing stack {stack['StackName']} : {str(e)}")
312331 continue
313332 print(f"Result : {result}")
314333
315- response_data = {"ApiVersionMapping": result}
334+ response_data = {"ApiVersionMapping" : result, "ApiArns": ','.join(api_gateway_arns) }
316335 cfnresponse.send(event, context, cfnresponse.SUCCESS, response_data)
317336
318337 except Exception as e :
319338 response_status = cfnresponse.FAILED
320339 reason = "Failed {} : {}".format(event["RequestType"], e)
321340
322341 Timeout : 300
323- MemorySize : 128
342+ MemorySize : 256
324343
325344 ApiVersionMapFunctionRole :
326345 Type : AWS::IAM::Role
@@ -996,6 +1015,7 @@ Resources:
9961015 - { ApiGateway: !Ref ApiGatewayRestApi }
9971016
9981017 ParallelClusterApiGatewayInvoke :
1018+ DependsOn : ApiVersionMap
9991019 Type : AWS::IAM::ManagedPolicy
10001020 Properties :
10011021 ManagedPolicyName : !Sub
@@ -1007,7 +1027,7 @@ Resources:
10071027 - Action :
10081028 - execute-api:Invoke
10091029 Effect : Allow
1010- Resource : !Sub "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:*/*/*"
1030+ Resource : !Split [",", !GetAtt ApiVersionMap.ApiArns]
10111031
10121032 CognitoPolicy :
10131033 Type : AWS::IAM::ManagedPolicy
0 commit comments