A Minimum Viable CloudFormation Template2019-08-19
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:
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:
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.
Hope this helps you with testing CloudFormation!
Are your Django project's tests slow? Read Speed Up Your Django Tests now!
One summary email a week, no spam, I pinky promise.
- Validating CloudFormation Templates With cfn-lint
- Running CloudFormation Drift Detection on All Your Stacks
- Testing Boto3 with Pytest Fixtures
© 2020 All rights reserved.