|
3 | 3 | "Mappings": {
|
4 | 4 | "RegionMap": {
|
5 | 5 | "us-east-1": {
|
6 |
| - "AMI": "ami-0b87d6d6549d6cf05" |
| 6 | + "AMI": "ami-0d6ee2886bd244da5" |
7 | 7 | },
|
8 | 8 | "us-east-2": {
|
9 |
| - "AMI": "ami-0897405d466f70917" |
| 9 | + "AMI": "ami-008bfa65989701e8e" |
10 | 10 | },
|
11 | 11 | "us-west-1": {
|
12 |
| - "AMI": "ami-08274e280c8adeb41" |
| 12 | + "AMI": "ami-0db27e770f106e446" |
13 | 13 | },
|
14 | 14 | "us-west-2": {
|
15 |
| - "AMI": "ami-0475ad550a49c0b32" |
| 15 | + "AMI": "ami-05612b746689f9b15" |
16 | 16 | },
|
17 | 17 | "ca-central-1": {
|
18 |
| - "AMI": "ami-0c552748a47926287" |
| 18 | + "AMI": "ami-0b0b3953456f25d6e" |
19 | 19 | },
|
20 | 20 | "eu-central-1": {
|
21 |
| - "AMI": "ami-0f0c16d879e0ea850" |
| 21 | + "AMI": "ami-07d555f7d8c193979" |
22 | 22 | },
|
23 | 23 | "eu-west-1": {
|
24 |
| - "AMI": "ami-09df159ef808ed76e" |
| 24 | + "AMI": "ami-0ddfa5404f0146080" |
25 | 25 | },
|
26 | 26 | "eu-west-2": {
|
27 |
| - "AMI": "ami-062148e3a494da1dd" |
| 27 | + "AMI": "ami-0347d4454a92a157c" |
28 | 28 | },
|
29 | 29 | "eu-west-3": {
|
30 |
| - "AMI": "ami-06ff6af6d123de5f9" |
| 30 | + "AMI": "ami-081f8109743149f39" |
31 | 31 | },
|
32 | 32 | "eu-north-1": {
|
33 |
| - "AMI": "ami-0acd50010ef1e1164" |
| 33 | + "AMI": "ami-0999d0a078a2f56bf" |
34 | 34 | },
|
35 | 35 | "sa-east-1": {
|
36 |
| - "AMI": "ami-007af0068115c5ffa" |
| 36 | + "AMI": "ami-023d0c38acceed5b2" |
37 | 37 | },
|
38 | 38 | "me-south-1": {
|
39 |
| - "AMI": "ami-06c7b69755f9cccbd" |
| 39 | + "AMI": "ami-001bcfe86ab58c383" |
40 | 40 | },
|
41 | 41 | "ap-east-1": {
|
42 |
| - "AMI": "ami-0ce622c442dd13ced" |
| 42 | + "AMI": "ami-0987274ff3aee58dd" |
43 | 43 | },
|
44 | 44 | "ap-south-1": {
|
45 |
| - "AMI": "ami-0716f3eb96636ba86" |
| 45 | + "AMI": "ami-0c1bb48c8752b48b4" |
46 | 46 | },
|
47 | 47 | "ap-northeast-1": {
|
48 |
| - "AMI": "ami-01ec0de36d77714fc" |
| 48 | + "AMI": "ami-0342e78cc98ac8477" |
49 | 49 | },
|
50 | 50 | "ap-northeast-2": {
|
51 |
| - "AMI": "ami-05fe1d3337c60b150" |
| 51 | + "AMI": "ami-010a4fc4563166544" |
52 | 52 | },
|
53 | 53 | "ap-southeast-1": {
|
54 |
| - "AMI": "ami-0e99496ad3a69b5d8" |
| 54 | + "AMI": "ami-07f2f557f3ca356c5" |
55 | 55 | },
|
56 | 56 | "ap-southeast-2": {
|
57 |
| - "AMI": "ami-0ff3bbab6addc3c87" |
| 57 | + "AMI": "ami-098f34af94a528f7e" |
58 | 58 | }
|
59 | 59 | }
|
60 | 60 | },
|
|
308 | 308 | "Handler": "index.lambda_handler",
|
309 | 309 | "Timeout": "600",
|
310 | 310 | "Code": {
|
311 |
| - "ZipFile": "# Copyright 2023 The MathWorks Inc.\nimport http, json, os, uuid, boto3\nfrom urllib.parse import urlparse\nfrom botocore.waiter import WaiterModel as Waiter, create_waiter_with_client as create_waiter\n\nINSTANCE_ID=os.environ['EC2_INSTANCE_ID']\nPROFILE_ID=os.environ['INSTANCE_PROFILE_ID']\nREGION=os.environ['AWS_REGION']\nLOG_GROUP='https://'+REGION+'.console.aws.amazon.com/cloudwatch/home?region='+REGION+'#logsV2:log-groups/log-group/$252Faws$252Flambda$252F'+os.environ['AWS_LAMBDA_FUNCTION_NAME']\n\ndef get_waiter_cfg(operation,argument,retry_error_codes):\n acceptors = [{\"matcher\":\"path\",\"expected\":True,\"argument\":argument,\"state\":\"success\"}] + [{\"matcher\":\"error\",\"expected\":error_code,\"state\":\"retry\",\"argument\":\"Code\"} for error_code in retry_error_codes]\n cfg={\"version\":2,\"waiters\":{\"CustomWaiter\":{\"delay\":3,\"operation\":operation,\"maxAttempts\":100,\"acceptors\": acceptors}}}\n return cfg\n\ndef get_resources(stack,response):\n cfn=boto3.client('cloudformation')\n res={}\n waiter_cfg=get_waiter_cfg(\"DescribeStackResource\",\"StackResourceDetail.ResourceStatus==`CREATE_IN_PROGRESS` || StackResourceDetail.ResourceStatus==`CREATE_COMPLETE`\",[\"ValidationError\"])\n waiter=create_waiter('CustomWaiter', Waiter(waiter_cfg), cfn)\n for id in [INSTANCE_ID, PROFILE_ID]:\n try:\n waiter.wait(StackName=stack,LogicalResourceId=id)\n resource=cfn.describe_stack_resource(StackName=stack,LogicalResourceId=id)\n res[id]=resource['StackResourceDetail']['PhysicalResourceId']\n except Exception as E:\n print(E)\n response['Reason']='Failed to get information on EC2 instance or instance profile. Check the log stream under the CloudWatch log group: '+LOG_GROUP\n return res\n\ndef send_response(request,response):\n url=urlparse(request['ResponseURL'])\n body=json.dumps(response)\n https=http.client.HTTPSConnection(url.netloc)\n https.request('PUT', url.path+'?'+url.query,body)\n return response\n \ndef lambda_handler(event,context): \n response={'StackId':event['StackId'],'RequestId':event['RequestId'],'LogicalResourceId':event['LogicalResourceId'],'Status':'SUCCESS'}\n stack=str(event['StackId']).split('/')[1]\n if 'PhysicalResourceId' in event:\n response['PhysicalResourceId']=event['PhysicalResourceId']\n else:\n response['PhysicalResourceId']=str(uuid.uuid4())\n if event['RequestType'] == 'Delete':\n return send_response(event,response)\n try:\n ec2=boto3.client('ec2')\n resources=get_resources(stack,response)\n waiter_cfg=get_waiter_cfg(\"AssociateIamInstanceProfile\",\"IamInstanceProfileAssociation.State==`associated` || IamInstanceProfileAssociation.State==`associating`\",[\"InvalidParameterValue\",\"IncorrectInstanceState\"])\n waiter=create_waiter('CustomWaiter', Waiter(waiter_cfg), ec2)\n waiter.wait(IamInstanceProfile={'Name':resources[PROFILE_ID]},InstanceId=resources[INSTANCE_ID])\n response['Reason']='Attached instance profile successfully'\n print(response['Reason'])\n except Exception as E:\n print(E)\n response['Status']='FAILED'\n if 'Reason' not in response:\n response['Reason']='Failed to attach instance profile to the EC2 instance. Check the log stream under the CloudWatch log group: '+LOG_GROUP\n return send_response(event,response)" |
| 311 | + "ZipFile": "# Copyright 2023-2024 The MathWorks, Inc.\nimport http, json, os, uuid, boto3\nfrom urllib.parse import urlparse\nfrom botocore.waiter import WaiterModel as Waiter, create_waiter_with_client as create_waiter\n\nINSTANCE_ID=os.environ['EC2_INSTANCE_ID']\nPROFILE_ID=os.environ['INSTANCE_PROFILE_ID']\nREGION=os.environ['AWS_REGION']\nLOG_GROUP='https://'+REGION+'.console.aws.amazon.com/cloudwatch/home?region='+REGION+'#logsV2:log-groups/log-group/$252Faws$252Flambda$252F'+os.environ['AWS_LAMBDA_FUNCTION_NAME']\n\ndef get_waiter_cfg(operation,argument,retry_error_codes):\n acceptors = [{\"matcher\":\"path\",\"expected\":True,\"argument\":argument,\"state\":\"success\"}] + [{\"matcher\":\"error\",\"expected\":error_code,\"state\":\"retry\",\"argument\":\"Code\"} for error_code in retry_error_codes]\n cfg={\"version\":2,\"waiters\":{\"CustomWaiter\":{\"delay\":3,\"operation\":operation,\"maxAttempts\":100,\"acceptors\": acceptors}}}\n return cfg\n\ndef get_resources(stack,response):\n cfn=boto3.client('cloudformation')\n res={}\n waiter_cfg=get_waiter_cfg(\"DescribeStackResource\",\"StackResourceDetail.ResourceStatus==`CREATE_IN_PROGRESS` || StackResourceDetail.ResourceStatus==`CREATE_COMPLETE`\",[\"ValidationError\"])\n waiter=create_waiter('CustomWaiter', Waiter(waiter_cfg), cfn)\n for id in [INSTANCE_ID, PROFILE_ID]:\n try:\n waiter.wait(StackName=stack,LogicalResourceId=id)\n resource=cfn.describe_stack_resource(StackName=stack,LogicalResourceId=id)\n res[id]=resource['StackResourceDetail']['PhysicalResourceId']\n except Exception as E:\n print(E)\n response['Reason']='Failed to get information on EC2 instance or instance profile. Check the log stream under the CloudWatch log group: '+LOG_GROUP\n return res\n\ndef send_response(request,response):\n url=urlparse(request['ResponseURL'])\n body=json.dumps(response)\n https=http.client.HTTPSConnection(url.netloc)\n https.request('PUT', url.path+'?'+url.query,body)\n return response\n \ndef lambda_handler(event,context): \n response={'StackId':event['StackId'],'RequestId':event['RequestId'],'LogicalResourceId':event['LogicalResourceId'],'Status':'SUCCESS'}\n stack=str(event['StackId']).split('/')[1]\n if 'PhysicalResourceId' in event:\n response['PhysicalResourceId']=event['PhysicalResourceId']\n else:\n response['PhysicalResourceId']=str(uuid.uuid4())\n if event['RequestType'] == 'Delete':\n return send_response(event,response)\n try:\n ec2=boto3.client('ec2')\n resources=get_resources(stack,response)\n waiter_cfg=get_waiter_cfg(\"AssociateIamInstanceProfile\",\"IamInstanceProfileAssociation.State==`associated` || IamInstanceProfileAssociation.State==`associating`\",[\"InvalidParameterValue\",\"IncorrectInstanceState\"])\n waiter=create_waiter('CustomWaiter', Waiter(waiter_cfg), ec2)\n waiter.wait(IamInstanceProfile={'Name':resources[PROFILE_ID]},InstanceId=resources[INSTANCE_ID])\n response['Reason']='Attached instance profile successfully'\n print(response['Reason'])\n except Exception as E:\n print(E)\n response['Status']='FAILED'\n if 'Reason' not in response:\n response['Reason']='Failed to attach instance profile to the EC2 instance. Check the log stream under the CloudWatch log group: '+LOG_GROUP\n return send_response(event,response)" |
312 | 312 | },
|
313 | 313 | "Environment": {
|
314 | 314 | "Variables": {
|
|
0 commit comments