-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_handler.py
46 lines (45 loc) · 1.45 KB
/
api_handler.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
import boto3
import json
file_url = 'https://template-stack-ce5f2a90.s3.amazonaws.com/vpc.yaml'
def lambda_handler(event, context):
print('EVENT:')
print(event)
data = json.loads(event['body'])
print('DATA:')
print(data)
APIParameters=[]
for key, value in data.items():
APIParameters.append({'ParameterKey': key, 'ParameterValue' : value, 'UsePreviousValue' : False, 'ResolvedValue' : 'string'})
print(APIParameters)
credentials = {
'aws_access_key_id' : 'AKIAXJJW7FYVH55GIN3D',
'aws_secret_access_key' : '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'
}
cloudform = boto3.client('cloudformation', 'us-east-1')
response = cloudform.create_stack(
StackName=data['EnvironmentName'],
TemplateURL=file_url,
Parameters = APIParameters,
DisableRollback = False,
TimeoutInMinutes=123,
Capabilities=[
'CAPABILITY_IAM',
],
Tags=[
{
'Key' : 'Name',
'Value' : 'AutoGenerated'
},
],
EnableTerminationProtection=False
)
response = {
"statusCode": 200,
"headers": {"Access-Control-Allow-Origin":"*"},
"body": json.dumps(
{"Status": "Success",
"Stack Name" : data['EnvironmentName'],
},
)
}
return response