AWS for DevOps — Infrastructure as Code
Chapter 8 — Infrastructure as Code
Infrastructure as Code (IaC) means managing AWS resources through template files instead of clicking through the console. CloudFormation is AWS’s native IaC service.
┌──────────────────────────────────────────────────┐
│ Infrastructure as Code on AWS │
│ │
│ CloudFormation CDK │
│ (YAML/JSON templates) (TypeScript/Python code) │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ template.yml │ │ cdk app │ │
│ │ ↓ │ │ ↓ │ │
│ │ Stack │ │ synth → │ │
│ │ ↓ │ │ CFN template│ │
│ │ AWS Resources│ │ ↓ │ │
│ └──────────────┘ │ Stack │ │
│ └──────────────┘ │
└──────────────────────────────────────────────────┘
What You’ll Learn
| Section | Topic | Key Concepts |
|---|---|---|
| 8.1 | CloudFormation Templates | YAML structure, resources, parameters, outputs |
| 8.2 | Intrinsic Functions | Ref, GetAtt, Sub, Join, If, Select |
| 8.3 | Stacks & Nested Stacks | Create, update, delete, cross-stack references |
| 8.4 | Change Sets & Drift Detection | Preview changes, detect manual modifications |
| 8.5 | CDK — Cloud Development Kit | TypeScript/Python IaC, constructs, synth |
| 8.6 | Practice Exercises | Hands-on scenarios |
Why IaC for DevOps?
| Manual (Console) | Infrastructure as Code |
|---|---|
| Click, click, click — one at a time | One template creates everything |
| “How was this configured?” — nobody knows | Template IS the documentation |
| Can’t reproduce in another region | Deploy the same template anywhere |
| Risky changes — no preview | Change Sets show exactly what will change |
| Configuration drift over time | Drift detection catches manual changes |
CloudFormation vs Terraform vs CDK
| Feature | CloudFormation | Terraform | CDK |
|---|---|---|---|
| Language | YAML / JSON | HCL | TypeScript, Python, Java, C# |
| Provider | AWS only | Multi-cloud | Compiles to CloudFormation |
| State management | AWS-managed | State file (S3 + DynamoDB) | AWS-managed (via CFN) |
| Drift detection | Built-in | terraform plan |
Via CloudFormation |
| Learning curve | Medium | Medium | Low (if you know programming) |
| Best for | AWS-native teams | Multi-cloud teams | Developers who prefer real code |
Next → CloudFormation Templates