AWS in 1 Min · Episode 166

AWS CloudFormation explained, Part 1: stacks and templates

Stacks and templates. Watch the one-minute video, then read the details.

David Gomez1:15 video · 2 min read

"CloudFormation runs your steps in order." It doesn't. You never write steps in CloudFormation. You describe what should exist, and CloudFormation works out what to create first, what can be created in parallel, and what has to wait. That shift, from instructions to a description, is the key to using it well.

Templates

AWS CloudFormation builds infrastructure from templates: text files written in YAML or JSON. A template has a few sections:

  • Resources (the only required section): every bucket, function, VPC or database you want, each with a logical name, a Type such as AWS::S3::Bucket, and its properties.
  • Parameters: inputs you pass at deploy time, such as an environment name or an instance size, so one template serves dev and production.
  • Outputs: values the stack returns after it is built, such as a website URL or a bucket name.
  • Optional extras such as Mappings and Conditions let one template adapt to different Regions or environments.

Order comes from references

When a server's properties reference a security group (with !Ref or !GetAtt), CloudFormation knows the group must exist first. These references build a dependency graph, and CloudFormation creates resources in the right order, in parallel where it can. For the rare case where there is no reference but order still matters, the DependsOn attribute makes it explicit.

Stacks

Deploy a template and you get a stack: all of its resources managed as one unit. You create, update and delete them together. Delete the stack and CloudFormation removes what it created (unless you protect a resource with a DeletionPolicy of Retain or Snapshot, which you should do for important data).

If something fails while a stack is being created or updated, CloudFormation rolls back by default, returning to the last working state instead of leaving half an environment behind. Since 2025, CloudFormation also runs pre-deployment validation that catches common failures, such as invalid property syntax or a name that already exists, before any resource is touched.

A common mistake is one giant stack for everything. Split by lifecycle instead: network, data and application stacks change at different speeds, and smaller stacks are easier to update safely.

Where AI fits

Describing what you want is exactly what language models are good at. Ask an assistant for "a VPC with two public and two private subnets and an Application Load Balancer" and it will draft the template. The open-source AWS IaC MCP server helps by giving the assistant current CloudFormation documentation and by checking the draft with cfn-lint (syntax and schema) and cfn-guard (security and compliance rules).

If your resources already exist, CloudFormation's IaC generator works the other way round: it scans resources in your account and generates a template from them, so you can bring them under management. Either way, review the result before you deploy it; Part 2 shows how.

Quick recap

  • Templates describe, in YAML or JSON; only Resources is required.
  • References set the order; CloudFormation works out the dependency graph.
  • A stack is one unit, and failures roll back by default.
AWS in 1 Min #166 · 1:15

Need an AWS expert on your team?

I'm David, an AWS expert and fractional cloud consultant. I work alongside your team to run your cloud and infrastructure: architecture, security, cost and day-to-day operations. You get senior AWS experience when you need it, without the cost of a full-time hire.

  • Architecture reviews and a clear plan for what to fix first
  • Security hardening: IAM, networking, audits
  • Lower AWS bills without slowing your team down
  • Hands-on help with AI workloads on AWS