-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayer_template.py
executable file
·58 lines (52 loc) · 1.18 KB
/
layer_template.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
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
"""
Script to create a new Lambda Layer CFN template via Troposphere
"""
from datetime import datetime
import argparse
from troposphere import (
Parameter,
Template,
GetAtt,
Sub,
Ref
)
from troposphere.awslambda import (
LayerVersion, Content
)
VERSION = datetime.utcnow().isoformat()
TEMPLATE = Template()
TEMPLATE.set_description(f'Template to create a Lambda layer. Version {VERSION}')
PARSER = argparse.ArgumentParser()
PARSER.add_argument(
'--runtimes', action='append', required=True
)
PARSER.add_argument(
'--s3-bucket', required=True
)
PARSER.add_argument(
'--s3-key', required=True
)
PARSER.add_argument(
'--json', action='store_true'
)
ARGS = PARSER.parse_args()
LAYER_NAME = TEMPLATE.add_parameter(Parameter(
'LayerName',
Type="String",
AllowedPattern='[a-z]+'
))
LAYER = TEMPLATE.add_resource(LayerVersion(
'LayerVersion',
CompatibleRuntimes=ARGS.runtimes,
Description=Sub(f'Layer ${{{LAYER_NAME.title}}}'),
LayerName=Ref(LAYER_NAME),
Content=Content(
S3Bucket=ARGS.s3_bucket,
S3Key=ARGS.s3_key
)
))
if ARGS.json:
print(TEMPLATE.to_json())
else:
print(TEMPLATE.to_yaml())