What CloudFormation is & the model

Templates, stacks, managed provisioning.

Beginner12 min · lesson 1 of 12

CloudFormation is AWS’s built-in infrastructure-as-code service. You write a template — a declarative document listing the AWS resources you want — and CloudFormation creates and manages them as a single unit called a stack. Because it is a native AWS service, there is nothing to install and no separate state file to babysit: AWS itself stores the stack state, tracks every resource, and knows how to create, update, and delete each one through its own APIs.

That native integration is the whole pitch versus a third-party tool. CloudFormation understands AWS resource lifecycles first-hand, handles rollback automatically when something fails, manages dependencies between resources, and is supported by AWS as the substrate under higher-level tools (SAM for serverless, the CDK, which synthesizes CloudFormation). The trade-off is that it is AWS-only — this is the AWS-native path, not a multi-cloud one.

Template to running infrastructure
1template
YAML/JSON declaration
2create stack
CloudFormation reads it
3provision
calls AWS APIs in order
4stack
managed as one unit
AWS stores the state and manages the resource graph — no external state file to store or lock.

Templates, stacks, resources

Three terms anchor everything. A template is the declarative source document. A resource is one AWS thing in it (an S3 bucket, an EC2 instance, an IAM role). A stack is the deployed instance of a template — the collection of resources managed together, created from one template, and deleted together. Update the template and update the stack; delete the stack and CloudFormation removes the resources it created, in dependency order.

The stack owns its resources
Deleting a stack deletes the resources it created — which is clean, but means a fat-fingered stack delete can take down a database. Conversely, editing a stack-managed resource by hand in the console creates drift (covered later) that the next update may undo. Treat the template as the source of truth and change infrastructure through the stack, not around it.