CloudFormation Templates and Stacks
What you'll learn: How CloudFormation templates serve as blueprints and stacks represent their deployed infrastructure.
The Blueprint and the Building
Think of AWS CloudFormation like construction: a template is your architectural blueprint (written in JSON or YAML), while a stack is the actual building constructed from those plans.
A CloudFormation template is a text file that declares what infrastructure you want—EC2 instances, S3 buckets, VPCs, databases, and their configurations. It's purely descriptive code sitting in a file. The template doesn't do anything on its own; it's just a specification.
A CloudFormation stack is what happens when AWS reads your template and provisions those resources in your account. When you create a stack, CloudFormation interprets the template, creates each resource in the correct order, and manages them as a single logical unit. That stack has a name, an ID, and represents real, running infrastructure consuming AWS resources.
The Relationship
One template can create multiple stacks. You might use the same web application template to deploy separate stacks for development, staging, and production environments. Each stack is independent—different resources, different lifecycles—but built from identical or similar template definitions.
When you update a template and apply changes to a stack, CloudFormation calculates what needs to change and updates only affected resources. If you delete a stack, CloudFormation tears down all associated resources automatically, maintaining that logical grouping.
This template-to-stack relationship mirrors what you learned with Terraform: templates are like your .tf configuration files, while stacks function similarly to Terraform's state-tracked resource collections.
Key Takeaway: CloudFormation templates are reusable infrastructure definitions (the "what"), while stacks are deployed instances of those templates (the "actual resources")—one template can spawn many stacks across environments or regions.