AWS CloudFormation
Infrastructure as code for provisioning AWS resources via templates
CloudFormation is like having blueprints for building a house, except for cloud infrastructure. Instead of manually clicking through the AWS console to create servers, databases, and networks (tedious and error-prone), you write a template (YAML or JSON) describing what you want. CloudFormation reads the blueprint and builds everything automatically, in the right order, with the right dependencies. Need to build the same infrastructure in another region? Use the same template. Need to tear it all down? One click deletes everything. It's infrastructure as code: version controlled, repeatable, and automated.
CloudFormation uses templates (JSON or YAML) to define AWS resources as stacks. Templates contain resources (required), parameters (inputs), outputs (values to export), conditions (conditional resource creation), and mappings (lookup tables). CloudFormation handles dependency resolution; if a resource depends on another, it creates them in the correct order.
Key Capabilities
Key features: change sets (preview changes before applying), stack policies (prevent accidental updates/deletes), drift detection (identify manual changes), and nested stacks (modularize templates).
Gotchas & Constraints
Gotcha #1: CloudFormation doesn't support all AWS features immediately; new services/features may lag behind console/API availability. Gotcha #2: Failed stack creation rolls back by default, deleting all resources; use --disable-rollback for debugging. Constraints: Template size limited to 51,200 bytes (use S3 for larger templates), maximum 500 resources per stack (use nested stacks for more), and stack updates can fail mid-way (use change sets to preview).
A company deploys a three-tier web application across dev, staging, and prod environments. Manually creating resources in each environment takes 4 hours and is error-prone. They create a CloudFormation template defining VPC, subnets, security groups, ALB, Auto Scaling Group, RDS, and ElastiCache. The template uses parameters for environment-specific values (instance types, database size). They deploy the stack in dev (10 minutes), test it, then deploy identical stacks in staging and prod using different parameter values. When they need to add a new feature requiring DynamoDB, they update the template, create a change set to preview changes, and apply it; CloudFormation adds DynamoDB without touching existing resources. For disaster recovery, they store templates in Git and can rebuild entire environments in any region in minutes.
The Result
consistent infrastructure, 90% faster deployments, and full audit trail via version control.