-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.py
More file actions
61 lines (53 loc) · 1.57 KB
/
function.py
File metadata and controls
61 lines (53 loc) · 1.57 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: utf-8 -*-
""" cfnmacro-vpc """
import json
import boto3
from subnets_maths import get_subnet_layers
from vpc import generate_vpc_template
def lambda_handler(event, context):
"""
cfnmacro-vpc Lambda Handler
"""
response = {
"status": "success",
"requestId": event['requestId']
}
region = event['region']
account_id = event['accountId']
transform_id = event['transformId']
fragment = event['fragment']
params = event['params']
param_values = event['templateParameterValues']
azs = boto3.client('ec2', region_name=region).describe_availability_zones(
Filters=[
{
'Name': 'state',
'Values': ['available']
}
]
)['AvailabilityZones']
azs_count = len(azs)
cidr_block = param_values['VpcCidr']
layers = get_subnet_layers(cidr_block, azs_count)
vpc_template = generate_vpc_template(layers, range(0, azs_count), cidr_block)
resources = vpc_template.to_dict()['Resources']
fragment['Resources'] = resources
response['fragment'] = fragment
print(response.keys())
print(response['requestId'])
print(response['status'])
return response
if __name__ == '__main__':
ret = lambda_handler(
{
'region': 'eu-west-1',
'accountId': '123456789012',
'requestId': 'notimportant',
'transformId': '',
'fragment': {},
'params': {},
'templateParameterValues': {'VpcCidr': '10.242.0.0/22'}
},
None
)
print(ret)