Back to Infrastructure as Code

AWS CDK

AWS-native Infrastructure as Code framework: write TypeScript/Python/Java/Go that compiles to CloudFormation. High-level constructs bundle AWS best-practice patterns.

Free (open-source Apache 2.0), pay only for AWS resources provisioned

AWS CDK in a Nutshell

AWS CDK meaning: AWS CDK (Cloud Development Kit) is Amazon's open-source Infrastructure as Code framework that lets you define AWS cloud resources using real programming languages ΓÇö TypeScript, Python, Java, C#, or Go ΓÇö and then synthesizes that code into AWS CloudFormation templates for deployment. In short, CDK is code that becomes infrastructure.

At its core, AWS CDK flips the IaC model on its head: instead of writing hundreds of lines of declarative YAML (CloudFormation) or a domain-specific config language (Terraform HCL), you write imperative code with full access to loops, conditionals, functions, and types ΓÇö then CDK compiles it down to the same safe, rollback-able CloudFormation stack AWS has run since 2011.

Definition

AWS CDK is an abstraction layer over CloudFormation. Every CDK construct maps (directly or transitively) to one or more CloudFormation resources. The App → Stack → Construct hierarchy mirrors how infrastructure is composed: an App contains Stacks, Stacks contain Constructs, and Constructs are the reusable building blocks (a single S3 bucket, an API Gateway + Lambda, or an entire VPC).

What CDK Is Used For ΓÇö Common Use Cases

  • Provisioning AWS infrastructure as code with the expressiveness of TypeScript/Python ΓÇö branching logic, typed interfaces, unit tests.
  • Sharing reusable infrastructure patterns internally via private construct libraries, or publicly via Construct Hub.
  • Adopting well-architected defaults out of the box ΓÇö the L2 construct library bakes in encryption-at-rest, least-privilege IAM, and lifecycle policies by default.
  • Multi-stack, multi-account, multi-region deployments ΓÇö CDK natively supports cross-account and cross-region stack wiring for hub-and-spoke and AWS Control Tower landing zones.
  • Migrating from hand-rolled CloudFormation ΓÇö CDK lets you import existing CFN resources (cdk import) and progressively refactor raw L1 mapping into curated L2 constructs.

Why Teams Pick CDK Over Terraform or Pulumi

Use case Why CDK wins
AWS-only shop Deepest AWS coverage, day-0 new-service support, native integration with AWS SAM, CloudFormation StackSets, and AWS Organizations.
Team already coding in TypeScript/Python Same language, same tooling, same IDE — no HCL or DSL to learn.
Compliance & rollback safety Synthesizes to CloudFormation, so you inherit change-set review, drift detection, and rollback triggers for free.
Reusable, opinionated patterns L2/L3 constructs encode AWS best-practice defaults that are tedious to hand-roll in Terraform modules.

Quick Example (TypeScript)

import * as cdk from "aws-cdk-lib";
import * as s3 from "aws-cdk-lib/aws-s3";

const app = new cdk.App();
const stack = new cdk.Stack(app, "BucketStack");
// L2 construct: encryption + versioning + lifecycle defaults included
new s3.Bucket(stack, "Docs", {
  versioned: true,
  encryption: s3.BucketEncryption.KMS,
  blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
});

~10 lines of TypeScript synthesize into ~80 lines of CloudFormation YAML ΓÇö and the IAM role, KMS key, and bucket policy are generated for you.

AWS CDK Meaning ΓÇö Inline Q&A

What does AWS CDK mean? AWS CDK stands for Amazon Web Services Cloud Development Kit ΓÇö an open-source Infrastructure as Code framework by Amazon that lets developers define AWS resources in TypeScript, Python, Java, C#, or Go and then synthesize that code into AWS CloudFormation templates for deployment.

Is AWS CDK the same as CloudFormation? No. CloudFormation is the deployment service; AWS CDK is a code-first authoring tool that generates CloudFormation templates. CDK output deploys via CloudFormation, so you inherit CloudFormation's drift detection, change sets, and rollback behaviors.

Is AWS CDK free? Yes. The CDK itself is open-source (Apache-2.0) and free; you only pay for the AWS resources your stacks provision. There is no per-stack or per-deploy charge for CDK itself.

AWS CDK vs Terraform ΓÇö which should I use? Choose AWS CDK if you are AWS-only, value typed code, and want day-0 support for new AWS services via raw L1 constructs. Choose Terraform if you need multi-cloud coverage (AWS + Azure + GCP + Kubernetes in one state) or your team already lives in HCL.

What languages does AWS CDK support? TypeScript, Python, Java, C#, Go, and .NET are first-class supported languages (JSII-compatible). Each language gets full construct-library bindings.

What is an L2 construct in AWS CDK? An L2 construct is a higher-level AWS CDK abstraction that wraps one or more L1 (raw CloudFormation) resources and bakes in AWS best-practice defaults ΓÇö for example, the s3.Bucket L2 enables encryption-at-rest, versioning, and a sensible lifecycle policy out of the box. L1 mappings (s3.CfnBucket) expose every raw CFN property with no defaults.

In a Nutshell

AWS CDK is Infrastructure as Code with the gloves off ΓÇö write real code, get real types, inherit CloudFormation's safety, and let the L2 construct library encode AWS best practices so you don't have to. If you're an AWS-centric team that prefers TypeScript over YAML/HCL, it is the most productive IaC choice available in 2026.


AWS Cloud Development Kit (CDK) is an Infrastructure as Code framework by Amazon that lets you define AWS cloud resources using TypeScript, Python, Java, C#, or Go. The defining twist: CDK code synthesizes into AWS CloudFormation templates, so you keep the safety of CloudFormation plus the expressiveness of a real programming language.\n\n## The Construct Hierarchy\n\nCDK organizes AWS abstractions into three construct levels:\n\n- L1 constructs ΓÇö thin wrappers over raw CloudFormation resources (s3.CfnBucket). 1:1 mapping with the CFN spec, every property is yours to set.\n- L2 constructs ΓÇö curated AWS best-practice defaults (s3.Bucket). Sensible defaults for encryption, versioning, and lifecycle policies baked in.\n- L3 constructs (patterns) ΓÇö opinionated multi-resource compositions (e.g., aws-s3-deployment.BucketDeployment provisions a bucket + Lambda deployer + CodePipeline trigger in one line).\n\nMost teams should default to L2 constructs ΓÇö the gap between raw CFN and L2 is the entire CDK value proposition.\n\n## Code Example (TypeScript)\n\nts\nimport * as cdk from "aws-cdk-lib";\nimport * as s3 from "aws-cdk-lib/aws-s3";\nimport * as lambda from "aws-cdk-lib/aws-lambda";\n\nexport class HelloStack extends cdk.Stack {\n constructor(scope: cdk.App, id: string) {\n super(scope, id);\n // L2 construct ΓÇö encryption, versioning, lifecycle defaults included\n const bucket = new s3.Bucket(this, "MyBucket", {\n versioned: true,\n encryption: s3.BucketEncryption.KMS\n });\n // Lambda with auto-generated IAM role permissions to read the bucket\n new lambda.Function(this, "Processor", {\n runtime: lambda.Runtime.NODEJS_20_X,\n handler: "index.handler",\n code: lambda.Code.fromAsset("lambda"),\n environment: { BUCKET: bucket.bucketName }\n });\n }\n}\n\n\nThe equivalent raw CloudFormation equivalent is ~120 lines of YAML. CDK's L2 constructs are the productivity multiplier.\n\n## Languages Supported\n\n| Language | Maintained By | IDE Tooling | Maturity |\n|---|---|---|---|\n| TypeScript | AWS (official) | First-class autocomplete & type-check | Most used |\n| Python | AWS (official) | Pyright + PyLance supported | Production-ready |\n| Java | AWS (official) | IntelliJ + Eclipse | Stable, verbose syntax |\n| C# | AWS (official) | Visual Studio / VS Code | Stable |\n| Go | Community (AWS-supported) | gopls / VS Code | GA since 2024 |\n\n## CDK vs CDK8s vs CDKTF\n\nCDK is AWS-only, but Amazon publishes two adjacent projects that bring the same model to other targets:\n\n- CDK8s ΓÇösynthesizes Kubernetes manifests in TS/Python/Go/Java. Write new k8s.Deployment(...) and emit YAML for kubectl apply.\n- CDKTF (CDK for Terraform) ΓÇö synthesize Terraform HCL from TS/Python/Go/Java/C#. Combines CDK's language ergonomics with Terraform's 3,900+ provider ecosystem.\n\nYou can mix-and-match all three inside a single CDK "app" ΓÇö same monorepo, three deploy targets.\n\n## Pricing\n\nCDK itself is free and open source under Apache 2.0. You pay only for the AWS resources you provision ΓÇö the EC2/S3/Lambda/whatever resources those stacks create. CloudFormation itself charges no separate fee. The AWS Construct Library is also Apache 2.0 and free.\n\n## When to Choose CDK vs Alternatives\n\n- Choose AWS CDK if your entire infra is on AWS and you want the deepest AWS abstraction with first-class IDE support.\n- Choose Terraform / OpenTofu if you're multi-cloud or want a provider ecosystem beyond AWS.\n- Choose Pulumi if you loved languages in CDK but their CDK state is a CloudFormation-shaped lock-in you dislike.\n- Choose Crossplane if you're a Kubernetes-native team and want your control plane to live inside the cluster.\n\n## Best For\n\n- AWS-only teams seeking a programming-language IaC experience\n- TypeScript/Python shops tired of YAML and CloudFormation JSON verbosity\n- Platform engineers building reusable construct libraries for application teams\n- Teams migrating from raw CloudFormation while keeping CFN as the deploy backend

What AWS CDK Actually Costs (verified 2026-11)

AWS CDK the framework is Apache-2.0 open source — the tool itself costs $0. There is no per-resource meter, no per-user license, and CloudFormation itself adds no charge. You pay for the infrastructure you provision (the same bill you would see with any IaC tool) plus the one-time engineering time to adopt constructs, context, and synth pipelines. The Construct Hub is free. CDK Pipelines are free to define; their compute bills like any other pipeline. If you are weighing CDK against Terraform on cost, the honest answer is: you are comparing engineering time and team fit — neither framework charges you for existing.

CDK vs Terraform vs Pulumi — honest trade-offs (verified 2026-11)

Constraint Pick Why
AWS-only, TypeScript/Python team CDK Native CloudFormation semantics, safest rollbacks, best AWS service coverage
Multi-cloud + hiring pool Terraform / OpenTofu 3,900+ providers; BSL vs MPL license choice is its own decision
Strong general-purpose engineers Pulumi Same TypeScript/Python mental model as the app itself
Kubernetes platform team Crossplane K8s-native state and RBAC; different abstraction, same job
Policy + audit at 100+ engineers HCP Terraform Premium Sentinel policy sets, audit logging, peak-metered from $0.99/resource/mo

License postures and figures checked 2026-11. Verify on the vendor pages — IaC economics move faster than docs do.

  • Best for: Infrastructure as Code
  • Pricing: Free (open-source Apache 2.0), pay only for AWS resources provisioned

Disclosure: We may earn a commission if you click this link and make a purchase, at no additional cost to you.

Visit AWS CDK

Features

✓

Drift Detection

Detect and report manual changes outside of IaC

CloudFormation drift detection

✗

Kubernetes-Native

Built on Kubernetes CRDs for native K8s experience

Not K8s-native, uses EKS construct library

✓

Module/Package Registry

Reusable infrastructure components managed via registry

AWS CDK Construct Library, Construct Hub

✗

Multi-Cloud Support

Provision infrastructure across AWS, Azure, GCP and others

AWS-focused, limited multi-cloud via custom resources

✗

Policy as Code

Define and enforce infrastructure policies programmatically

AWS Config rules, Service Control Policies (separate)

✓

Preview/Plan

Preview infrastructure changes before applying them

cdk diff and CloudFormation change sets

✓

Programming Languages

Use general-purpose languages instead of DSL

TypeScript, Python, Java, C#, Go, .NET

✓

Secret Management

Handle sensitive values like passwords and API keys

AWS Secrets Manager, Parameter Store integration

✓

State Management

Track and manage infrastructure state over time

AWS CloudFormation state management

✓

Team Collaboration

Multi-user support with RBAC and audit logs

AWS IAM, CloudFormation StackSets for multi-account

Best For

Find the right DevOps tools for your specific needs. AWS CDK is featured in these buying guides:

Related Links