Troposphere helper functions

25/11/2016
Posted in AWS Blog
25/11/2016 Ben Bridts

Here at Cloudar we write a lot of CloudFormation to provision AWS resources. We really like the way CloudFormation creates resources in parallel and how it provides an easy way to clean up all created resources.

However writing CloudFormation can be a bit of a pain. Even though AWS made this a lot easier with YAML support, for  big templates we still use Troposphere. Troposphere is a python package that provides a simple (one-on-one) mapping to CloudFormation. It has some advantages like offline error checking, but its greatest assets is that it can be used in combination with a real programming language.

Having python available to write templates, leads to writing helper functions to simplify some verbose constructs and bundle commonly used resources. Today we’re happy to publish this as on open source package.

You can find our troposphere helpers on pypi or on github.

Here is an example of how it can simplify CloudFormation code:

This is the normal way to add Option Settings to an ElasticBeanstalk configuration in Troposphere:

config_template = template.add_resource(ConfigurationTemplate(
    "ConfigTemplate",
    OptionSettings=[
        OptionSettings(
            Namespace='aws:autoscaling:asg',
            OptionName='MinSize',
            Value='2'
        ),
        OptionSettings(
            Namespace='aws:autoscaling:asg',
            OptionName='MaxSize',
            Value='4'
        ),
        # ...
    ],
))

Using our helper function this can be reduced to:

config_template = t.add_resource(ConfigurationTemplate(
    "ConfigTemplate",
    OptionSettings=add_option_settings({
        'aws:autoscaling:asg': {
            'MinSize': '2',
            'MaxSize': '4',
        },
        # ...
    })
))

And this is only one of the different functions in there (and we expect to keep adding to this over time).

Do you have any helper functions you’ve written? Let us know!

  • SHARE

Leave a Reply

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

LET'S WORK
TOGETHER

Need a hand? Or a high five?
Feel free to visit our offices and come say hi
… or just drop us a message

We are ready when you are

Cloudar NV – Operations

De Villermontstraat 9
2550 Kontich (Antwerp)
Belgium

info @ cloudar.be

+32 3 450 67 18

Cloudar NV – HQ

Veldkant 33A
2550 Kontich (Antwerp)
Belgium

VAT BE0564 763 890

This contact form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

© 2020 – CLOUDAR NV

contact
  • SHARE