Intro to CloudFormation

Infrastructure as Code.

Posted by Mike Apted on Wednesday, March 9, 2016

Over the last several months I’ve had the opportunity to start working directly with AWS CloudFormation and it’s already become a staple of any new AWS related project.

CloudFormation is a service that allows you define, create, iterate and destroy AWS infrastructure from a JSON formatted template or set of templates (you can also template external resources with more advanced tooling).

At its simplest you define a Stack in JSON, and hand it off to CloudFormation to manage the provisioning of all the resources. If you want to modify or add a resource to your setup you simply update the template and hand it back to CloudFormation to make those updates for you. CloudFormation will manage things like inferring any resource dependencies, and create the resources in the appropriate order.

An example of an incredibly simple stack template, that creates an AWS S3 bucket, would look like this:

  "Resources" : {
    "S3Bucket" : {
      "Type" : "AWS::S3::Bucket"

This is an incredibly simple example, but that’s the concept. In fact, this barely scratches the surface of the possible complexity of CloudFormation but you can get started with something that simple.

The high level takeaway is that the service allows you to define your infrastructure as code, maintain it in source control along with your application code, and easily manage the lifecycles of your environments.