-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcfn.py
73 lines (46 loc) · 1.86 KB
/
cfn.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
# Creates or updates cloudformation stack
import argparse
import yaml
import boto
import boto.s3
import boto.cloudformation
from templates import static_site as template
def get_deploy_config():
text = open("config/config.yml", 'r')
return yaml.load(text)
def cfn_connect(region_name):
return boto.cloudformation.connect_to_region(region_name)
def cfn_update(cfn_conn, stack_name, template_body, parameters):
# only valid capability
capabilities = ["CAPABILITY_IAM"]
cfn_conn.update_stack(stack_name, template_body=template_body,
capabilities=capabilities, parameters=parameters)
def cfn_create(cfn_conn, stack_name, template_body, parameters):
# only valid capability
capabilities = ["CAPABILITY_IAM"]
cfn_conn.create_stack(stack_name, template_body=template_body,
capabilities=capabilities, parameters=parameters)
def update(config, params):
cfn_conn = cfn_connect(config['region_name'])
cfn_update(cfn_conn, config['stack_name'], template.get(), params)
print("Updating stack: {0}".format(config['stack_name']))
def create(config, params):
cfn_conn = cfn_connect(config['region_name'])
cfn_create(cfn_conn, config['stack_name'], template.get(), params)
print("Creating stack: {0}".format(config['stack_name']))
def parse_args():
parser = argparse.ArgumentParser(
description='Creates or updates a Cloudformation stack')
parser.add_argument('-c', '--create', action='store_true')
return parser.parse_args()
def main(args=None):
args = parse_args()
config = get_deploy_config()
params = config['params'].items()
# in case create flag is active do create, update is default action
if args.create:
return create(config, params)
update(config, params)
if __name__ == "__main__":
main()