AWS Cloud Development Kit (CDK) – SAA-C03 Study Guide
The AWS Cloud Development Kit (CDK) is an open-source software development framework to define your cloud infrastructure in code and provision it through AWS CloudFormation. Unlike traditional CloudFormation templates (JSON/YAML), CDK allows you to use the power of modern programming languages.
Core Concepts
1. Constructs
Constructs are the basic building blocks of CDK apps. A construct represents a “cloud component” and encapsulates everything CloudFormation needs to create that component.
- Level 1 (L1): Cfn Resources. These are direct 1:1 mappings to CloudFormation resources (e.g.,
CfnBucket). - Level 2 (L2): Intent-based APIs. These include sensible defaults and boilerplate (e.g.,
s3.Bucket). - Level 3 (L3): Patterns. These are higher-level abstractions designed to help you complete common tasks (e.g.,
ApplicationLoadBalancedFargateService).
2. The App, Stacks, and Synthesis
An App is the root of your CDK project. It contains one or more Stacks (the unit of deployment, mapping to a CloudFormation Stack). When you run cdk synth, the CDK translates your code into a CloudFormation template.
Comparison: CDK vs. CloudFormation vs. SAM
| Feature | AWS CDK | CloudFormation | AWS SAM |
|---|---|---|---|
| Language | Imperative (TS, Python, Java) | Declarative (JSON, YAML) | Declarative (YAML extension) |
| Abstraction | High (Constructs) | Low (Resource level) | Medium (Serverless focus) |
| Best For | Complex logic & reusability | Simple infrastructure | Serverless/Lambda apps |
| Provisioning | Via CloudFormation | Direct | Via CloudFormation |
Exam Tips and Gotchas
- CDK Bootstrap: Before deploying a CDK app to an environment, you must run
cdk bootstrap. This creates an S3 bucket and IAM roles required to store assets during deployment. - The “Synth” Step: The exam may ask how CDK interacts with AWS. Remember: CDK synthesizes to CloudFormation. It does not bypass it.
- Imperative vs. Declarative: CDK is imperative (you use loops and if-statements), but the resulting CloudFormation is declarative.
- Construct Hub: If a scenario mentions sharing reusable architecture patterns across a large organization, CDK and the Construct Hub are the primary answers.
Decision Matrix / If–Then Guide
- If you need to use loops, logic, or object-oriented principles to define infra: Choose AWS CDK.
- If you want to minimize the amount of code for a standard Fargate + ALB setup: Choose CDK L3 Patterns.
- If you need to deploy an application quickly without a “compilation” step: Choose CloudFormation.
- If you are specifically building a Serverless application with local testing needs: Choose AWS SAM.
Topics covered :
Summary of key subtopics covered in this guide:
- CDK Definition and Relationship with CloudFormation
- Construct Levels (L1, L2, L3 Patterns)
- CDK Workflow (Init, Synth, Diff, Deploy, Bootstrap)
- Comparison with SAM and CloudFormation
- Environment Bootstrapping Requirements
AWS CDK Architectural Flow
Integrations: Seamlessly manages IAM Roles, VPC networking, and Security Groups using L2 constructs. No more manual ARN referencing.
Automatically handles Least Privilege via grantRead() methods.
Speed: CDK allows for rapid prototyping. Use CDK Watch for hot-swapping Lambda code without a full CloudFormation redeploy (Development only).
High-level patterns scale complex architectures in minutes.
Efficiency: CDK itself is free. However, it generates standard AWS resources. Use cdk diff to see resource changes before deploying to avoid accidental costly resource creation.
Tagging all resources for cost allocation is one line of code in CDK.
Production Use Case: Microservices
A company needs to deploy 50 identical microservice stacks. Instead of copying 50 YAML files, they create a single CDK Construct and loop through a list of service names, ensuring consistency and reducing human error across the fleet.