in util/vpc-tools/create_stack.py [0:0]
def create_stack(stack_name, template, region='us-east-1', blocking=True,
temp_bucket='edx-sandbox-devops', parameters=[],
update=False):
cfn = boto.connect_cloudformation()
# Upload the template to s3
key_pattern = 'devops/cloudformation/auto/{}_{}'
key_name = key_pattern.format(stack_name, basename(template))
template_url = upload_file(template, temp_bucket, key_name)
# Reference the stack.
try:
if update:
stack_id = cfn.update_stack(stack_name,
template_url=template_url,
capabilities=['CAPABILITY_IAM'],
tags={'autostack':'true'},
parameters=parameters)
else:
stack_id = cfn.create_stack(stack_name,
template_url=template_url,
capabilities=['CAPABILITY_IAM'],
tags={'autostack':'true'},
parameters=parameters)
except Exception as e:
print(e.message)
raise e
status = None
while blocking:
sleep(5)
stack_instance = cfn.describe_stacks(stack_id)[0]
status = stack_instance.stack_status
print(status)
if 'COMPLETE' in status:
break
if status in FAILURE_STATES:
raise Exception('Creation Failed. Stack Status: {}, ID:{}'.format(
status, stack_id))
return stack_id