Skip to main content
Welcome. In this lesson we introduce the AWS Cloud Development Kit (CDK), explain how it maps to AWS CloudFormation, and show how to adopt CDK as infrastructure as code (IaC) in development and CI/CD pipelines. The AWS CDK lets you define cloud resources using familiar programming languages instead of hand-writing raw CloudFormation templates. A CDK application is still Infrastructure as Code: the CDK framework synthesizes your app into AWS CloudFormation templates, and CloudFormation deploys those templates to create and manage resources. Using CDK gives you the benefits of programming-language features—loops, conditionals, abstractions, testing—while producing CloudFormation stacks under the hood. You can author CDK applications in several officially supported languages, enabling teams to use their preferred toolchains:
  • TypeScript
  • JavaScript
  • Python
  • Java
  • C#
  • Go
Because CDK provides higher-level constructs, it is often easier to author and reuse infrastructure definitions than by calling the AWS SDK (for example, Boto3) directly. CDK constructs encapsulate common configuration and best practices so you can compose infrastructure faster and with fewer mistakes.
A simple diagram showing a developer using AWS CDK with Python to provision AWS EC2. The boxed icons illustrate "AWS CDK + Python = AWS EC2."
Core concept — constructs Constructs are the primary building blocks in CDK. They exist at multiple abstraction levels:
A slide titled "AWS CDK – Hierarchy of Constructs" showing a CDK App with Stacks and nested Construct levels (L1, L2, L3). It explains L1 as raw CloudFormation resources, L2 as CDK wrappers with sensible defaults, and L3 as high-level patterns combining multiple resources.
  • L1 (low-level): direct CloudFormation resource representations (one-to-one mapping).
  • L2 (higher-level): typed APIs with sensible defaults and convenience methods.
  • L3 (patterns): opinionated, reusable architecture patterns that combine multiple resources (for example, SNS+SQS fan-out or event-driven patterns).
L2 and L3 constructs accelerate development by encapsulating architecture best practices, reducing boilerplate, and making stacks easier to reason about. CDK CLI — common commands Use the CDK CLI during local development, CI, and pipelines. The most commonly used commands are:
cdk synth generates the AWS CloudFormation template (YAML/JSON) from your CDK app. It does not deploy resources; use cdk deploy for deployment. Always inspect synthesized templates to audit changes before applying them to production.
CI/CD with CDK A typical CI/CD workflow for CDK looks like:
  1. Store CDK code in a Git repository.
  2. Run unit tests, linters, and type checkers.
  3. Run cdk synth to generate CloudFormation templates (or validate changes).
  4. Deploy via a pipeline that either runs cdk deploy or hands off synthesized templates to CloudFormation.
Using CDK in pipelines enables you to include:
  • Unit and integration tests for constructs and stacks
  • Linting and static analysis (e.g., type checks for TypeScript)
  • Automated synth and policy checks (security and compliance)
  • Environment promotion (dev → staging → prod) with parameterization
A "Features" slide with five numbered cards, each showing a colorful circular icon and label: 01 Declarative approach, 02 Component reusability, 03 AWS Construct Library, 04 Automated synthesis, and 05 Environment agnosticism.
In practice you typically run your CDK commands from a build runner (for example, CodeBuild, GitHub Actions, GitLab CI). The build step packages artifacts, runs tests, and either produces synthesized templates or performs the deployment.
A diagram of an AWS CDK pipeline where a developer pushes code to AWS CodeCommit, triggering CodePipeline and CodeBuild, then AWS CloudFormation to deploy resources. The CloudFormation stack contains icons for S3, EC2, VPC and RDS.
Example — Python CDK stack (S3 bucket) Below is a minimal Python CDK stack that creates an Amazon S3 bucket with versioning enabled and a removal policy. This demonstrates how concise resource declaration is with CDK.
Be cautious with RemovalPolicy.DESTROY for production data. This policy removes the bucket and its contents when the stack is deleted. For production, prefer RemovalPolicy.RETAIN and implement lifecycle/longevity strategies for data.
CDK adoption best practices Follow these recommendations when adopting CDK at scale:
  • Encapsulate repeatable patterns into reusable constructs.
  • Parameterize stacks for environment-specific configuration instead of hardcoding values.
  • Enable CloudFormation stack policies and safeguards for sensitive resources.
  • Use CDK bootstrapping and the CDK toolkit for multi-account, multi-region deployments (managed via AWS Organizations).
  • Test CDK code with unit tests and integration tests, and validate synthesized templates before deployment.
  • Integrate policy-as-code and security checks into the pipeline (for example, using automated checks against synthesized templates).
A presentation slide titled "AWS CDK – Best Practices." It lists recommendations: use CDK constructs for reusability, parameterize instead of hardcoding, enable CloudFormation stack policies, use the CDK toolkit for multi-account deployments, and test CDK infrastructure before deployment.
Summary This lesson covered:
  • What the AWS CDK is and how it synthesizes to CloudFormation
  • Construct abstractions (L1, L2, L3) and why they matter
  • Common CDK CLI commands and typical CI/CD flows
  • A simple Python example that provisions an S3 bucket
  • Best practices for building safe, reusable infrastructure code
Further reading and references Thanks for reading this lesson.

Watch Video