A Minimum Viable CloudFormation Template

Sometimes when testing CloudFormation features I need a minimum viable template to try that feature with.

(Like my Ansible Minimum Viable Playbook).

Here’s the basic template I use:

AWSTemplateFormatVersion : 2010-09-09 Resources : Topic : Type : AWS::SNS::Topic

It has two things:

The format version. This is one of the useless things in CloudFormation. They left a version specifier and then haven’t changed it for (at time of writing) 9 years. But, I’m paranoid, so I make sure my templates have the version specifier just in case they release a breaking change. Just in case.

An SNS topic resource. I’ve found SNS topics are about the fastest resources to create or update, taking about 10 seconds.

I can then change it according to what I want to test, for example adding parameters, outputs, or referencing resources. This is easier and faster than testing as part of a larger CloudFormation template.

Testing a Bug

As an example, I used this template to test for an old bug.

Previously, if you changed a template to only add a DeletionPolicy to a resource, CloudFormation would succeed but not actually add the policy. Then if you deleted the stack, CloudFormation would delete the resource, even though you thought it wouldn’t.

I tested this in a minute with my MVP template. I created a stack from the above basic template, then updated it with this template:

AWSTemplateFormatVersion : 2010-09-09 Resources : Topic : DeletionPolicy : Retain # Added Type : AWS::SNS::Topic

The I deleted the stack and SNS retained the topic.

Nice to know AWS have fixed the bug, although I don’t recall it ever being publicly acknowledged, or mentioned on the release history.

Fin

Hope this helps you with testing CloudFormation!

—Adam

Working on a Django project? Check out my book Speed Up Your Django Tests which covers loads of best practices so you can write faster, more accurate tests.

Subscribe via RSS, Twitter, or email: Your email address:

One summary email a week, no spam, I pinky promise.

Related posts:

Tags: aws, cloudformation

© 2020 All rights reserved.