Last active
January 11, 2020 22:58
-
-
Save suhussai/3197e7cbddaf0199403be557d3491169 to your computer and use it in GitHub Desktop.
boto3 cloud formation template body (TemplateBody) example using local yml file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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