In short
CloudFormation YAML for a real app can run to hundreds of lines. The AWS CDK lets you write the same infrastructure in TypeScript or Python, with loops, functions and autocomplete, and still deploy it through CloudFormation.
The AWS Cloud Development Kit lets you define infrastructure in languages such as TypeScript or Python, and it synthesises that code into CloudFormation templates. Higher-level constructs create sensible defaults with much less code.

Think of it like this
Ready-made modular kitchen units
Designing a kitchen brick by brick means specifying every hinge. A modular kitchen shop in Chandigarh sells ready units: 'sink unit', 'tall pantry unit', each with sensible fittings built in, and you can still customise a drawer. CDK constructs are those units. One line for a bucket comes with secure defaults, and CDK writes the detailed CloudFormation plan for you.
Watch it happen
From code to stack
1/5You write an App with one or more Stacks, each containing constructs like Bucket and Function.
The big ideas
What you need to know
Construct levels
L1 constructs (CfnBucket) map one-to-one to CloudFormation. L2 constructs (Bucket) add defaults and helper methods. L3 patterns build whole architectures.
Grant methods
bucket.grantRead(fn) writes a least-privilege IAM policy for you, which is easier and safer than writing JSON by hand.
Bootstrap once
cdk bootstrap creates an S3 bucket, ECR repo and roles in each account and Region you deploy to.
It's still CloudFormation
Limits, drift and rollbacks all behave like CloudFormation. Knowing templates helps you debug CDK.
See it in code
Walk through the code
1import { App, Stack, StackProps, RemovalPolicy, Duration } from "aws-cdk-lib";2import { Construct } from "constructs";3import * as s3 from "aws-cdk-lib/aws-s3";4import * as lambda from "aws-cdk-lib/aws-lambda";5 6class UploadsStack extends Stack {7 constructor(scope: Construct, id: string, props?: StackProps) {8 super(scope, id, props);9 10 const bucket = new s3.Bucket(this, "Uploads", {11 encryption: s3.BucketEncryption.S3_MANAGED,12 blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,13 enforceSSL: true,14 removalPolicy: RemovalPolicy.RETAIN,15 });16 17 const fn = new lambda.Function(this, "Indexer", {18 runtime: lambda.Runtime.NODEJS_22_X,19 handler: "index.handler",20 code: lambda.Code.fromAsset("lambda"),21 timeout: Duration.seconds(10),22 environment: { BUCKET: bucket.bucketName },23 });24 25 bucket.grantRead(fn);26 }27}28 29const app = new App();30new UploadsStack(app, "UploadsStack", { env: { region: "ap-south-1" } });1/6CDK v2 imports: core classes plus service modules from aws-cdk-lib.
CDK v2 in TypeScript. Everything lives in the single aws-cdk-lib package. Run npx cdk bootstrap once, then npx cdk diff and npx cdk deploy.
Save yourself the pain
Common mistakes
Oops
Running cdk deploy without looking at cdk diff, and replacing a database by renaming its construct ID.
Do this instead
Changing a construct's ID changes its logical ID, which can mean delete and recreate. Always read the diff for 'replace' lines.
Oops
Forgetting to bootstrap a new Region, then getting a confusing deploy error.
Do this instead
Run cdk bootstrap aws://ACCOUNT/REGION once for each account and Region you deploy to.
Your mission
Your first CDK stack
Quick check
What does cdk synth produce?
Go deeper
- 1Run cdk init in TypeScript or Python and deploy a stack with one S3 bucket.
- 2Run cdk synth and read the generated CloudFormation template.
- 3Use an L2 or L3 construct, such as an ECS Fargate service pattern, and compare it with raw CloudFormation.
More topics at this stop
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.