Copyright (c) 2026 MindMesh Academy. All rights reserved. This content is proprietary and may not be reproduced or distributed without permission.

4.1.4. AWS CDK: Constructs, Apps, and Synthesis

šŸ’” First Principle: CloudFormation templates are powerful but verbose. A simple three-tier web application might require 500+ lines of YAML. AWS CDK lets you define the same infrastructure in 50 lines of TypeScript, Python, or Java — using real programming language features (loops, conditionals, functions, classes) that YAML simply can't express. CDK is not a replacement for CloudFormation; it synthesizes CloudFormation templates. CloudFormation does the actual provisioning.

CDK Construct Levels:
LevelDescriptionAbstraction
L1 (Cfn constructs)Direct 1:1 mapping to CloudFormation resources (e.g., CfnBucket)Low — matches CF exactly
L2 (AWS constructs)Curated, opinionated wrappers with sensible defaults (e.g., Bucket)Medium — simplifies common patterns
L3 (Patterns)Multi-resource patterns for common architectures (e.g., ApplicationLoadBalancedFargateService)High — entire subsystems
CDK Workflow:
Key CDK Commands:
CommandWhat It Does
cdk initCreate a new CDK project from template
cdk synthSynthesize CloudFormation template (doesn't deploy)
cdk diffCompare current stack to deployed stack
cdk deploySynthesize and deploy to AWS
cdk destroyDelete the stack and its resources
cdk bootstrapCreate the CDK Toolkit stack (S3 bucket, ECR repo) in the account/region

CDK Bootstrap: Before you can deploy CDK applications, you must bootstrap the target account/region. cdk bootstrap creates the CDKToolkit CloudFormation stack, which includes an S3 bucket for storing CDK assets (Lambda code, Docker images) and an ECR repository. In multi-account deployments, you bootstrap each target account.

CDK Context: Key-value pairs stored in cdk.context.json that capture environment-specific values (e.g., "what AZs are available in this account?"). CDK queries AWS APIs on first use and caches the results so future synths are deterministic.

āš ļø Exam Trap: CDK synthesizes to CloudFormation, so all CloudFormation limits apply. The maximum template size is 1MB (S3) or 51KB (direct upload). Large CDK applications may require nested stacks to stay within limits. CDK handles this automatically when using the NestedStack construct — but it's a constraint to be aware of for the exam.

Reflection Question: Your team uses Python and wants to define a three-tier web application with an ALB, Auto Scaling Group, and RDS instance using CDK. A new developer asks "does CDK replace CloudFormation?" How do you explain the relationship between CDK and CloudFormation, and what CDK command would they run first to preview what will be deployed?

Alvin Varughese
Written byAlvin Varughese
Founder•15 professional certifications