-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateStack.py
More file actions
33 lines (30 loc) · 939 Bytes
/
CreateStack.py
File metadata and controls
33 lines (30 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import json
import boto3
import os
client = boto3.client('cloudformation')
def lambda_handler(event, context):
lambda_client = boto3.client('lambda')
role_response = (lambda_client.get_function_configuration(
FunctionName = os.environ['AWS_LAMBDA_FUNCTION_NAME'])
)
print(role_response)
roleArn = role_response['Role']
accountId = context.invoked_function_arn.split(":")[4]
commandType = event['id']
capabilities = ['CAPABILITY_IAM']
stackName = commandType
print(commandType)
templateUrl = f"https://remediation-cfns-{accountId}.s3.amazonaws.com/{commandType}.yaml"
print(templateUrl)
print(event)
print(context)
response = client.create_stack(
StackName=stackName,
TemplateURL=templateUrl,
Capabilities=capabilities,
RoleARN=roleArn,
)
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}