What is Infrastructure as Code?

Describe your AWS resources in files, and let CloudFormation create, update, and delete them for you.

1 min read

So far we've created resources by clicking in the console or running CLI commands. That works for learning, but it doesn't scale. How do you recreate everything in a new account? Review changes before they happen? Know who changed what?

Infrastructure as Code (IaC) means describing infrastructure in text files that live in Git, just like application code. AWS CloudFormation reads these files (templates) and makes AWS match them.

Think of it like this

Clicking in the console is like cooking from memory: it works, but you can't reproduce it exactly. A CloudFormation template is a written recipe. Anyone can follow it and get the same dish, and you can see every change in the recipe's history.

What you get

  • Repeatable: spin up identical dev, staging, and prod environments.
  • Reviewable: infrastructure changes go through pull requests.
  • Safe updates: CloudFormation works out the order of changes and rolls back if something fails.
  • Easy cleanup: delete the stack and every resource in it goes away.

Your options

  • CloudFormation templates in YAML or JSON
  • AWS CDK: write infrastructure in TypeScript, Python, Java, C#, or Go, which generates CloudFormation
  • AWS SAM: a CloudFormation shorthand focused on serverless apps
  • Third-party tools such as Terraform

Key takeaways

  • IaC describes infrastructure in version-controlled files.
  • CloudFormation creates and updates resources to match a template, rolling back on failure.
  • CDK and SAM are friendlier ways to produce CloudFormation.

Check your understanding

Pick an answer to see the explanation.

  1. 1. What happens if a CloudFormation stack update fails halfway?