Infrastructure as Code (IaC) Managing infrastructure through code with CloudFormation and CDK
CloudFormation Key Concepts
- Stacks: Unit of deployment, create/update/delete together
- StackSets: Deploy stacks across accounts and regions
- Change Sets: Preview changes before applying
- Drift Detection: Identify manual changes to resources
- Nested Stacks: Modular templates using AWS::CloudFormation::Stack
- Custom Resources: Lambda-backed for unsupported resources
CloudFormation vs CDK vs Terraform
| Feature | CloudFormation | CDK | Terraform |
|---|
| Language | JSON/YAML | TypeScript, Python, etc. | HCL |
| State | AWS-managed | Synthesizes to CFn | Local/remote state file |
| Drift Detection | Built-in | Via CFn | terraform plan |
| Multi-cloud | AWS only | AWS only | Multi-cloud |
Update Behaviors
No Interruption
Resource updated in place with no downtime
Some Interruption
Brief disruption during update
Replacement
New resource created, old one deleted
Exam Focus Areas
- DeletionPolicy: Retain keeps resources when stack is deleted
- UpdateReplacePolicy: Retain keeps old resource during replacement
- cfn-init for bootstrapping EC2 instances with metadata
- cfn-signal with WaitCondition/CreationPolicy for readiness signaling