Skip to content

Instantly share code, notes, and snippets.

@suhussai
Last active January 11, 2020 22:58
Show Gist options
  • Save suhussai/3197e7cbddaf0199403be557d3491169 to your computer and use it in GitHub Desktop.
Save suhussai/3197e7cbddaf0199403be557d3491169 to your computer and use it in GitHub Desktop.
boto3 cloud formation template body (TemplateBody) example using local yml file
import boto3, yaml, json
# file must in the same dir as script
template_file_location = 'example_cloud_formation.yml'
stack_name = 'test_cloud_formation'
# read entire file as yaml
with open(template_file_location, 'r') as content_file:
content = yaml.load(content_file)
# convert yaml to json string
content = json.dumps(content)
cloud_formation_client = boto3.client('cloudformation')
print("Creating {}".format(stack_name))
response = cloud_formation_client.create_stack(
StackName=stack_name,
TemplateBody=content,
Parameters=[{ # set as necessary. Ex:
'ParameterKey': 'KEY',
'ParameterValue': 'VALUE'
}]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment