Skip to main content
In this lesson we’ll cover the AWS Cloud Development Kit (AWS CDK) — an infrastructure-as-code (IaC) framework that lets you model and provision AWS resources using familiar programming languages such as Python, JavaScript/TypeScript, Java, and C#. Instead of authoring large JSON or YAML templates, you express infrastructure as constructs and classes in your preferred language and synthesize them into CloudFormation templates.
A diagram showing a developer using Python plus the AWS CDK to provision an AWS EC2 instance (Python + AWS CDK = AWS EC2). The AWS CDK logo appears in the top-left corner.

Why use AWS CDK?

CDK provides the benefits of a general-purpose programming language combined with the reliability of CloudFormation deployments:
  • Use familiar programming constructs: loops, conditionals, functions, modules, packages, and test frameworks.
  • Build higher-level abstractions (constructs) that encapsulate best practices and are reusable across teams and projects.
  • Rely on a rich AWS Construct Library for common services and patterns.
  • CDK synthesizes your code into CloudFormation templates, so deployments still go through AWS CloudFormation.

Typical CDK workflow

  1. Write code that composes constructs into stacks inside a CDK app.
  2. Run cdk synth to synthesize AWS CloudFormation templates from your CDK app.
  3. Run cdk deploy to hand the templates to AWS CloudFormation, which creates or updates the stacks.
A diagram of the AWS CDK workflow: a CDK app containing stacks and constructs is run through "cdk synth" to produce CloudFormation templates, then "cdk deploy" sends those templates to AWS CloudFormation which creates stacks.

Core CDK concepts

  • Constructs: opinionated building blocks that represent one or more AWS resources.
  • AWS Construct Library: pre-built constructs that map to AWS services and common patterns.
  • Automated synthesis: transforms your code into CloudFormation templates.
  • Reusability: parameterize constructs and stacks for environment-specific configuration.
A slide titled "Features" showing five numbered panels with colored icons. The panels list: 01 Declarative Approach, 02 Component Reusability, 03 AWS Construct Library, 04 Automated Synthesis, and 05 Environment Agnosticism.

CDK in CI/CD pipelines

Because CDK outputs CloudFormation templates, it integrates cleanly with AWS-native CI/CD services. A typical pipeline:
  • Source: CodeCommit, GitHub, or another repository.
  • CI: CodeBuild (or another runner) runs tests, builds artifacts, and runs cdk synth.
  • CD: Deploys the synthesized CloudFormation templates via AWS CloudFormation to create/update resources.
A diagram of an AWS CDK pipeline showing CodeCommit as the source feeding AWS CodePipeline and CodeBuild, which triggers AWS CloudFormation to deploy a CloudFormation stack. The stack contains icons for S3, EC2, VPC, and RDS, with arrows showing the end-to-end flow.

Quick reference: commands and minimal Python example

Common CLI commands (CDK v2): Minimal Python CDK stack (CDK v2 style):
This example creates a versioned Amazon S3 bucket. Running cdk synth generates a CloudFormation template representing the bucket; cdk deploy hands that template to CloudFormation to create the bucket in your AWS account.

Considerations and best practices

CDK is ideal for teams that want to express infrastructure using a programming language, reuse constructs across projects, and integrate infrastructure code into unit tests and CI/CD pipelines.
Because CDK synthesizes to CloudFormation, be aware of CloudFormation limits (template size, resource counts). Very large apps may require splitting into multiple stacks or using nested stacks and adjustments for limits.

Summary

AWS CDK combines the expressiveness of general-purpose programming languages with CloudFormation’s deployment model. Use constructs to package best practices, synthesize to CloudFormation for reliable deployment, and integrate CDK into CI/CD pipelines for repeatable, automated infrastructure delivery.

Watch Video