On this page
On this page
- What Is CloudFormation
- Template Anatomy
- Parameters โ Dynamic Inputs
- Mappings โ Static Lookup Tables
- Outputs and Cross-Stack References
- Conditions
- Intrinsic Functions
- Pseudo Parameters
- Update Behaviors
- DeletionPolicy
- Stack Policies
- Don't confuse the three protection mechanisms
- Rollbacks and Troubleshooting
- Stack Creation Failure
- Stack Update Failure
- UPDATE_ROLLBACK_FAILED
- DELETE_FAILED
- StackSet OUTDATED Status
- ChangeSets
- Nested Stacks vs Cross-Stack References
- StackSets โ Multi-Account and Multi-Region Deployment
- Permission Models
- Service Role (CloudFormation IAM Role)
- Capabilities
- Custom Resources
- Dynamic References
- RDS + Secrets Manager Integration (Two Patterns)
- EC2 Bootstrapping in CloudFormation
- cfn-init and AWS::CloudFormation::Init
- cfn-signal and WaitCondition
- cfn-hup โ Updating Running Instances
- Macros and Transform
- Drift Detection
- Resource Import
- AWS Service Catalog
- Key Exam Scenarios
- CloudWatch Integration
- Automatically Published
- Requires Setup
CloudFormation
CloudFormation lets you define your AWS infrastructure as code โ written in YAML or JSON. Instead of clicking through the console to create a VPC, subnets, security groups, an RDS database, and an EC2 instance, you write a template that describes all of them, and CloudFormation creates and manages the entire stack for you.
The Infrastructure as Code Idea
Manual infrastructure is fragile. You can't easily reproduce it, you can't review changes before applying them, and you can't roll back when something goes wrong. Infrastructure as code solves all three problems: your template lives in version control, changes go through code review, and CloudFormation can roll back a failed update automatically.
How Stacks Work
You upload a template to CloudFormation and it creates a stack โ a collection of AWS resources managed as a single unit. To update your infrastructure, you update the template and submit a change set, which shows you exactly what will be created, modified, or deleted before anything actually changes. When you delete the stack, CloudFormation deletes all the resources it created.
Templates
A CloudFormation template has a few key sections:
Parameters โ inputs you supply at deploy time (environment name, instance type, database password). This lets one template serve dev, staging, and prod with different values.
Resources โ the actual AWS resources to create. Each resource has a type
(e.g., AWS::EC2::Instance) and properties. Resources can reference each other
using !Ref and !GetAtt.
Outputs โ values exported from the stack (a load balancer URL, a bucket name, a VPC ID) that other stacks or systems can use.
Drift Detection
After resources are created, someone might manually change them through the console. CloudFormation can detect this drift โ the difference between what the template says and what actually exists โ and report which resources have been modified outside of CloudFormation's control.
The Bigger Picture
CloudFormation is the foundation that higher-level tools like AWS CDK (Cloud Development Kit) build on. CDK lets you define infrastructure using TypeScript, Python, or Java, then synthesizes it into a CloudFormation template. Under the hood, CDK deploys are just CloudFormation stacks.