CloudFormation

I’ve been using AWS CloudFormation for many years to manage infrastructure created on the Amazon Web Services platform. Trying to configure such an environment manually is tedious and error-prone. It’s more efficient and reliable to do so automatically – managing infrastructure as code. It’s actually a few years since I last used CloudFormation professionally, and I was pleased to discover some new functionality while making some updates for a personal project.

CloudFormation stacks can only manage a maximum of 500 resources. Nested stacks are used to avoid reaching this limit: a nested stack can itself contain another 500 resources but only counts as one within its parent. Nested stacks are also the primary form of abstraction within CloudFormation. A stack can be created multiple times with different parameter values. Unfortunately they’re also a little clunky.

  • It’s hard to refactor by moving resources around. Moving a resource from one stack to another will create an entirely new version within AWS. If the resource has a unique name then the update will fail (the new resource is created before the old one is removed, so there’s a collision). If the resource has internal state (e.g. data) then that will be lost when the old resource is deleted.
  • Updates start at the root and ripple down through the tree of stacks. Making a simple change can take a long time as every stack is checked for changes.

It’s now possible to import existing resources into a CloudFormation stack. If somebody happened to create a server manually then you can now add it to your stack and start managing it properly. This also makes it possible to move resources between stacks, solving the first problem above (refactoring).

More excitingly, AWS have released the Cloud Development Kit back in 2019 which makes it easy to create and manage multiple stacks programmatically using a language like TypeScript or Python. This makes it possible to solve the second problem: abstraction in CloudFormation can instead be handled within a general-purpose programming language eliminating the need for complex hierarchies of nested stacks.

I’m now starting to migrate all my CloudFormation templates to CDK TypeScript. The CDK itself outputs a template so I’m still on familiar ground and it’s easy to see where the code isn’t quite lined up with the current configuration. Watch this space for further updates…

This entry was posted in Uncategorized. Bookmark the permalink. Trackbacks are closed, but you can post a comment.

Post a Comment

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*
*