100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

AWS CDK Cheat Sheet

AWS CDK Cheat Sheet

Explains AWS CDK's constructs, stacks, and synthesis model for defining CloudFormation infrastructure using TypeScript or Python.

2 PagesIntermediateFeb 15, 2026

CDK CLI Basics

Core commands for bootstrapping and deploying a CDK app.

bash
cdk init app --language=typescript   # scaffold new projectcdk bootstrap aws://ACCOUNT_ID/REGION  # one-time setup per account/regioncdk synth                             # generate CloudFormation templatecdk diff                              # compare deployed stack vs local codecdk deploy                            # deploy the stackcdk destroy                           # tear down the stack

Define a Stack (TypeScript)

An S3 bucket and Lambda function defined as CDK constructs.

typescript
import * as cdk from 'aws-cdk-lib';import * as s3 from 'aws-cdk-lib/aws-s3';import * as lambda from 'aws-cdk-lib/aws-lambda';export class MyStack extends cdk.Stack {  constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {    super(scope, id, props);    const bucket = new s3.Bucket(this, 'MyBucket', {      versioned: true,      removalPolicy: cdk.RemovalPolicy.DESTROY,    });    new lambda.Function(this, 'MyFunction', {      runtime: lambda.Runtime.NODEJS_18_X,      handler: 'index.handler',      code: lambda.Code.fromAsset('lambda'),      environment: { BUCKET_NAME: bucket.bucketName },    });  }}

Key Concepts

CDK-specific building blocks.

  • Construct- Basic building block; wraps one or more CloudFormation resources
  • L1 Construct (CFN Resource)- Direct 1:1 mapping to a CloudFormation resource, e.g. CfnBucket
  • L2 Construct- Higher-level, opinionated wrapper with sane defaults, e.g. s3.Bucket
  • L3 Construct (Pattern)- Composed of multiple L2 constructs to solve a common architecture pattern
  • Stack- Unit of deployment; maps 1:1 to a CloudFormation stack
  • App- The root construct tree containing one or more stacks
  • Synthesis- The process of turning CDK code into a CloudFormation template (cdk synth)
Pro Tip

Run 'cdk diff' before every deploy in CI — it catches unintended resource replacements (like a renamed S3 bucket) that would otherwise cause downtime or data loss during 'cdk deploy'.

Was this cheat sheet helpful?

Explore Topics

#AWSCDK#AWSCDKCheatSheet#CloudComputing#Intermediate#CDKCLIBasics#DefineAStackTypeScript#KeyConcepts#Explains#DataStructures#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet