CDK is DNA
Every cell in your body contains the same DNA, and from it an entire, consistent body grows. Infrastructure as code gives software the same power: a description in code from which identical environments grow — again and again, in any account or Region. The AWS Cloud Development Kit (CDK) lets you write that DNA in a programming language you already know.
Why grow bodies from DNA instead of by hand?
Clicking through the AWS console is like assembling a person by hand: slow, error-prone, and impossible to reproduce exactly.
| By hand (console) | From DNA (CDK) |
|---|---|
| Steps live in someone's memory | Steps live in Git, reviewed like code |
| Dev and prod drift apart | Every environment grows from the same code |
| Hard to rebuild after a disaster | cdk deploy regrows the whole body |
| Permissions written manually | grant… methods generate least-privilege policies |
| Nobody knows why something exists | Code + commit history explain it |
How CDK works
Your TypeScript (DNA) ──cdk synth──► CloudFormation template (proteins) ──cdk deploy──► AWS resources (the living body)
CDK code is synthesised into AWS CloudFormation templates; CloudFormation then creates, updates or deletes resources safely, rolling back if something fails.
The building blocks
| CDK concept | Analogy | What it is |
|---|---|---|
| App | The whole society's genome | The root of your CDK program |
| Stack | A family that's deployed together | A unit of deployment (one CloudFormation stack) |
| Construct | A gene that builds an organ — or a whole human | A reusable building block |
| L1 constructs | Raw genetic letters | Direct mappings of CloudFormation resources (CfnTable) |
| L2 constructs | Genes with sensible defaults | Friendly APIs with best-practice defaults (dynamodb.Table, NodejsFunction) |
| L3 constructs (patterns) | Whole organs | Multi-resource patterns (e.g. an API + function + table) — including your own |
In this handbook, one human = one construct. The Waiter construct contains everything the Waiter needs: memory, brain functions, senses, voice permissions and health alarms. Grow it once, reuse it anywhere.
The commands you'll use
| Command | What it does |
|---|---|
cdk init app --language typescript |
Create a new project |
cdk bootstrap |
One-time setup per account/Region (creates resources CDK needs to deploy) |
cdk synth |
Generate the CloudFormation template (check your DNA) |
cdk diff |
Show what will change before deploying |
cdk deploy |
Grow or update the body in AWS |
cdk destroy |
Remove the stack (careful with data!) |
DNA mutations, safely
Changing CDK code and redeploying is like a controlled mutation: CloudFormation works out the minimal set of changes. A few rules keep mutations safe:
- Run
cdk diffbefore every deploy — look especially for replacements of stateful resources (tables, buckets). - Protect memory — set
removalPolicy: RETAIN(and deletion protection) on production tables so a stack deletion doesn't erase data. - Avoid hard-coded physical names for resources that may need replacing; let CDK generate names.
- Keep secrets out of the DNA — reference them from Secrets Manager.
CDK vs other ways of writing DNA
CloudFormation (YAML/JSON), Terraform, Pulumi and the Serverless Framework solve the same problem. CDK's strengths: real programming languages (loops, types, functions), reusable constructs, and grant methods that make least privilege easy. Choose one and use it consistently — the habit of growing from code matters more than the tool.