How Do You Use Boto to Deploy a CloudFormation Stack?

Problem scenario
You want to use Boto to deploy a CloudFormation stack. Where can you find an example of a Python program that deploys a CloudFormation stack?

Solution
Prerequisites

This assumes you have installed Boto. If you need assistance, see this posting.

Procedures

  1. Create a .json template file. For this proof of concept, you can use this file.
  2. Run a program like this:
import boto3
cloudf = boto3.client('cloudformation', region_name='us-west-1', aws_access_key_id='AKIAabcdefgh12345', aws_secret_access_key='SOMETHING1234here/moretext')
json_stack=open('lampstack.json', 'r').read()
cloudf.create_stack(StackName='continualstack', TemplateBody=json_stack, Parameters = [ { 'ParameterKey': 'KeyName', 'ParameterValue': 'foobar'}, {'ParameterKey': 'DBPassword', 'ParameterValue': 'verycont'}, {'ParameterKey': 'DBUser', 'ParameterValue': 'contuser'}, {'ParameterKey': 'DBRootPassword', 'ParameterValue': 'contpassword'}] )

Leave a comment

Your email address will not be published. Required fields are marked *