AWS Cloud Development Kit
Infrastructure as real code
A framework for defining AWS infrastructure in familiar programming languages (TypeScript, Python, Java, C#, Go); the `cdk synth` command translates code into a CloudFormation template, then `cdk deploy` deploys it.
- Cost$ Low
- Difficulty●●●●●
- Costs money when idle?No
- Serverless
- In examsDVA · SAA
Think of it asLike writing a recipe in your own language, then having someone translate it into the head chef's language (CloudFormation) to cook.
When to use it
✓ Use it when
Dev teams that want to write infrastructure as code with loops, functions, types, and reusable constructs.
✗ Avoid it when
You need a multi-cloud tool or the team is used to pure declarative definitions → Terraform / CloudFormation.
Common uses
- Build a serverless stack (API Gateway + Lambda + DynamoDB) in a few dozen lines of code
- Package internal constructs shared across many teams
- Create infrastructure for multiple dev/staging/prod environments from the same code
What does it cost?
- Pricing model: Free; you only pay for the AWS resources the stack creates.
`cdk bootstrap` creates an S3 bucket and an ECR repo to hold assets; old assets gradually pile up and still incur storage costs.
When the question says define infrastructure in a programming language like TypeScript or Python, choose CDK; for declarative YAML/JSON templates, CloudFormation; for serverless apps with shorthand syntax, SAM; CDK ultimately produces CloudFormation.
Frequently asked questions
How is CDK different from CloudFormation?
CloudFormation uses declarative YAML/JSON templates. CDK lets you write infrastructure in a programming language (TypeScript, Python, Java and more) with loops, functions and types, then synthesizes a CloudFormation template to deploy. So CDK still runs on CloudFormation: stacks, rollback and drift detection work as usual.
What are L1, L2 and L3 constructs?
L1 maps one-to-one to CloudFormation resources (names start with Cfn) and you fill in every property. L2 is a convenient abstraction with sensible defaults and helper methods (for example granting permissions). L3 (patterns) combines several resources into a complete solution, such as a service behind a load balancer.
What are the main CDK commands and what is cdk bootstrap for?
cdk synth generates the CloudFormation template, cdk diff compares it with what is deployed, and cdk deploy deploys it. Before the first deploy in an account and Region you must run cdk bootstrap, which creates supporting resources such as an S3 bucket for assets and required roles.