USD ($)
$
United States Dollar
Euro Member Countries
India Rupee
د.إ
United Arab Emirates dirham
ر.س
Saudi Arabia Riyal

AWS Cloud Development Kit (CDK)

Lesson 19/50 | Study Time: 35 Min

CloudFormation uses YAML. Terraform uses HCL. Both are good tools, but they are configuration languages, not real programming languages. AWS CDK takes a different approach entirely.

It lets you define your infrastructure using a programming language you already know — Python, TypeScript, Java, or others — and then automatically generates the CloudFormation template for you behind the scenes.

For developers who are more comfortable writing code than configuration files, CDK feels natural and powerful.

How CDK Works

CDK sits on top of CloudFormation. You write infrastructure code in your preferred language, and CDK compiles it into a CloudFormation template and deploys it as a CloudFormation stack.

You get the full power of a programming language — loops, conditionals, functions, classes, imports — applied to infrastructure definition. This is something YAML and HCL cannot do naturally.

Key CDK Concepts


1. App: The top-level container for your entire CDK project. Every CDK project starts with an App.


2. Stack: A CDK Stack maps directly to a CloudFormation stack. It is where you define your resources. A single CDK App can contain multiple stacks — one for networking, one for compute, one for databases.


3. Constructs: Constructs are the building blocks of CDK. Every resource you define is a construct. CDK has three levels of constructs:

L2 constructs are what you will use most. They handle the boilerplate for you while still letting you customise what you need.

A Simple Example

Here is what creating an S3 bucket looks like in CDK using Python — compared to doing the same thing in CloudFormation YAML:

CloudFormation YAML:


CDK in Python:


Both produce the same result. But with CDK, you can now use Python logic around it — create ten buckets with a loop, apply conditions, share the bucket definition across multiple stacks as a reusable function.

CDK Toolkit — The Key Commands


cdk diff is particularly useful — it is CDK's equivalent of a change set preview. Always run it before deploying to production.

CDK vs. CloudFormation vs. Terraform

When to Use CDK

CDK is a strong choice when:


1. Your team is developer-heavy and more comfortable with Python or TypeScript than YAML.

2. You need to build reusable infrastructure components that behave like libraries.

3. Your infrastructure has complex logic — dynamic resource creation, conditional configurations, looping over environments.

4. You want full IDE support — autocomplete, type checking, inline documentation — while writing infrastructure.


CDK is not the best choice when your team is already deeply invested in Terraform or when you need multi-cloud infrastructure management.

Drew Collins

Drew Collins

Product Designer
Profile

Class Sessions

1- What is DevOps? Principles, Culture, and Practices 2- The DevOps Lifecycle 3- Introduction to Cloud Computing 4- AWS Global Infrastructure 5- Core AWS Services Overview 6- Git Fundamentals 7- Branching Strategies 8- Pull Requests and Code Review Best Practices 9- Integrating Git with AWS CodeCommit and GitHub 10- Managing Secrets and Sensitive Files in Repositories 11- What is CI/CD? 12- Building Pipelines with AWS CodePipeline and CodeBuild 13- Automated Testing in CI 14- Deployment Strategies 15- Using GitHub Actions and Jenkins on AWS 16- Why Infrastructure as Code (IaC)? 17- AWS CloudFormation 18- Terraform on AWS 19- AWS Cloud Development Kit (CDK) 20- IaC Best Practices 21- Docker Fundamentals 22- Amazon ECR 23- Deploying Containers with Amazon ECS 24- Kubernetes Basics and Amazon EKS 25- Integrating Containers into CI/CD Pipelines 26- Serverless Computing Concepts and Use Cases 27- Building and Deploying AWS Lambda Functions 28- Event-Driven Automation with Amazon EventBridge 29- Orchestrating Workflows with AWS Step Functions 30- API Gateway Integration for Serverless APIs 31- Introduction to MLOps 32- Training and Deploying Models with Amazon SageMaker 33- Automating ML Pipelines with SageMaker Pipelines 34- Using Amazon CodeWhisperer and AI Tools for Code Automation 35- AI-Powered Testing, Anomaly Detection, and Incident Prediction 36- Observability Fundamentals 37- Amazon CloudWatch 38- Distributed Tracing with AWS X-Ray 39- Centralised Logging with Amazon OpenSearch Service 40- Setting Up Automated Alerts and Incident Response Workflows 41- Shift-Left Security 42- IAM Roles, Policies, and Least-Privilege Access 43- Static Code Analysis and Vulnerability Scanning in CI/CD 44- AWS Security Hub, GuardDuty, and Config for Compliance 45- Secrets Management with AWS Secrets Manager and Parameter Store 46- AWS Well-Architected Framework 47- Auto Scaling and Elastic Load Balancing for Resilience 48- Cost Monitoring with AWS Cost Explorer and Budgets 49- Disaster Recovery Strategies 50- Preparing Your Project for Production