AWS CDK lets you define cloud infrastructure in familiar programming languages - Python, TypeScript, Java - and synthesise it into CloudFormation. Compared to writing raw CloudFormation or Terraform HCL, CDK gives you loops, conditionals, type safety, and the ability to share constructs across teams as libraries.
This series works through practical CDK patterns using Python, using a consistent use case across all parts to make trade-offs easy to compare.
Use case
Deploy an AWS Lambda function that processes files uploaded to an S3 bucket. Configuration - bucket name, log level, Lambda timeout - varies per environment (dev, staging, prod).
Simple infrastructure by design. The focus is on the CDK patterns, not the resources.
The series
Chapter 1 - Project setup and bootstrapping
Getting a CDK project off the ground - directory structure, virtual environments, bootstrapping an AWS account, and understanding the synth/deploy cycle.
Chapter 2 - Managing configuration and context (coming soon)
How environment-specific values flow into CDK stacks. Four approaches, each with different trade-offs:
- Part 1 - Local static config (
cdk.json) (coming soon) - Part 2 - Local dynamic config (coming soon)
- Part 3 - AWS SSM Parameter Store (coming soon)
- Part 4 - AWS Secrets Manager (coming soon)
| Approach | Version controlled | Supports secrets | Change without redeploy | Shared across stacks |
|---|---|---|---|---|
| Local static | Yes | No | No | No |
| Local dynamic | No | Partial | Yes | No |
| SSM Parameter Store | No | No | Yes | Yes |
| Secrets Manager | No | Yes | Yes | Yes |
Chapter 3 - Writing and sharing constructs (coming soon)
Building reusable constructs - L1, L2, L3 abstractions, packaging as a library, and sharing across projects or teams.
Chapter 4 - Testing CDK stacks (coming soon)
Unit testing stacks with assertions, snapshot testing, and integration testing patterns.
Chapter 5 - CI/CD with CDK (coming soon)
Automating deployments with CDK Pipelines - self-mutating pipelines, promoting changes across environments, and handling rollbacks.
Notes
- All examples use Python and CDK v2
- Steps are tested on WSL2/Ubuntu on Windows and native macOS terminal
- More chapters added as I work through these patterns