AWS CloudFormation
Also known as: CFN, CDK, AWS CDK, IaC, stack, CloudFormation template
CloudFormation is AWS's native infrastructure-as-code (IaC) service.
You write templates (JSON or YAML) describing AWS resources -- EC2 instances, S3 buckets, VPCs, IAM roles -- and CloudFormation creates, updates, and deletes them as a managed stack. It's the AWS-native alternative to Terraform for deploying AWS infrastructure as code.
AWS CloudFormation, explained at three levels
At home
CloudFormation lets you describe your entire AWS infrastructure in a text file and have AWS create it automatically. Instead of clicking through the AWS console to create each resource by hand, you write a template and CloudFormation builds everything in the right order.
At work
Teams use CloudFormation to ensure their AWS infrastructure is consistent, reproducible, and version-controlled. The same template can create identical dev, staging, and production environments -- eliminating 'it works in dev but not in production' infrastructure differences.
At home
CloudFormation templates have sections: Parameters (inputs you provide at deployment), Resources (what to create -- the only required section), Outputs (values to export), Conditions (conditional resource creation), and Mappings (lookup tables). Resources reference each other with Ref and Fn::GetAtt intrinsic functions -- CloudFormation handles dependency ordering automatically.
At work
CloudFormation stack updates use change sets (preview of what will change before applying), enabling safe incremental changes. Stack policies prevent accidental updates to critical resources. Cross-stack references via Outputs/Exports enable modular architectures. StackSets deploy the same template across multiple AWS accounts and regions simultaneously -- essential for multi-account AWS Organizations structures.
At home
CloudFormation custom resources allow provisioning non-AWS resources (third-party services, on-premises systems) via Lambda functions. Resource providers (CloudFormation Registry) extend CloudFormation to manage resources from other services (Datadog monitors, MongoDB Atlas clusters) using the same template language.
At work
AWS CDK compiles high-level constructs (L2/L3) to CloudFormation templates. L2 constructs provide sensible defaults (an S3 Bucket construct automatically configures encryption, versioning, and block public access best practices). CDK Stacks compose constructs into deployable units; CDK Pipelines automate self-mutating CI/CD for CDK applications. Service Catalog wraps CloudFormation templates with governance controls for end-user infrastructure provisioning.
Real-world examples
At home
Sophie created a CloudFormation template that provisions her personal website infrastructure: an S3 bucket with static hosting, a CloudFront distribution, an ACM certificate, and Route 53 DNS records. She can recreate the entire setup in any AWS account in 10 minutes.
At work
Thomas's team uses AWS CDK for all their infrastructure. Python CDK code defines VPCs, ECS clusters, RDS databases, and IAM roles. The CDK pipeline deploys to dev on every commit, staging on merge to main, and production on tag -- all with the same code, different parameters.
Common confusions
- CloudFormation and Terraform do the same thing — Both are infrastructure-as-code tools, but CloudFormation only manages AWS resources. Terraform supports 100+ cloud providers. CloudFormation has deeper AWS integration (change sets, stack policies, drift detection) but Terraform is preferred for multi-cloud or hybrid environments.
- You must use YAML/JSON to write CloudFormation — AWS CDK allows you to write CloudFormation in TypeScript, Python, Java, C#, or Go. CDK compiles your code to a CloudFormation template. For new projects, CDK is generally preferred over raw YAML/JSON for its type safety and reuse capabilities.
For analysts
CloudFormation stack deployments create auditable, repeatable infrastructure -- which matters for compliance and cost attribution. BAs doing cloud cost analysis can use CloudFormation stack tags to attribute AWS costs to specific projects, teams, or environments.
History & origin
AWS launched CloudFormation in 2011 as one of the earliest infrastructure-as-code services. It predated Terraform by two years and became the dominant way AWS users automated infrastructure at scale. CloudFormation stacks provide lifecycle management -- resources created together are tracked together and can be deleted together. AWS CDK (Cloud Development Kit, 2019) added a programming language layer on top of CloudFormation, allowing Python, TypeScript, and Java to define infrastructure that compiles to CloudFormation templates.