Pyhton & Troposphere - AWS Greatness

Using troposhere for cloudformation magic.

Written by Rory Savage in September 16, 2015   |   Link

Troposhere is my new favorite python module. It's a module that allows you to create AWS Cloudformation templates and because it's a module, you have all of the programatic power of python to generate your stacksi any way you wish.

Examples

A simple example to create an instance would look like this:

>>> from troposphere import Ref, Template
>>> import troposphere.ec2 as ec2
>>> t = Template()
>>> instance = ec2.Instance("myinstance")
>>> instance.ImageId = "ami-951945d0"
>>> instance.InstanceType = "t1.micro"
>>> t.add_resource(instance)
<troposphere.ec2.Instance object at 0x101bf3390>
>>> print(t.to_json())
{
    "Resources": {
        "myinstance": {
            "Properties": {
                "ImageId": "ami-951945d0",
                "InstanceType": "t1.micro"
            },
            "Type": "AWS::EC2::Instance"
        }
    }
}