AWS CDK explained simply: the AWS Cloud Development Kit lets you define cloud infrastructure in a real programming language — TypeScript, Python, Java, C#, Go or JavaScript — instead of writing long YAML templates by hand. Should you use it? If you are a developer who already thinks in code, yes: the CDK turns infrastructure into something you can loop over, test, reuse and review like any other software, while CloudFormation still does the actual provisioning underneath.
The problem it solves is the verbosity of declarative templates. A modest application needs a network, a database, a queue, a function and the permissions tying them together, and describing all of that in YAML can run to hundreds of lines of near-identical structure. The CDK replaces that repetition with constructs: reusable building blocks you compose in code, with loops for repeated resources, conditions for environment differences, and functions for patterns you use again and again.
Key takeaways
- The AWS CDK is an open-source framework for defining AWS infrastructure in a programming language; it synthesises your code into CloudFormation templates.
- CDK is not a separate provisioning engine — CloudFormation still creates, updates and rolls back the resources.
- Constructs come in three levels: L1 maps directly to CloudFormation resources, L2 adds curated defaults, and L3 bundles whole architecture patterns.
- The workflow is init, bootstrap, synth, diff, deploy and destroy, and you can test stacks with unit tests before deploying.
- CDK version 2 became generally available in December 2021; version 1 reached end of support in June 2023.
- CDK fits AWS-focused development teams best; multi-cloud estates usually need a different tool.
What is the AWS CDK?
The AWS Cloud Development Kit is an open-source software development framework for modelling and provisioning cloud infrastructure using familiar programming languages. You write code that describes the infrastructure you want, and the CDK converts that code into CloudFormation templates that AWS then deploys. Everything in a CDK application is a construct: a cloud component that can represent a single resource, such as a storage bucket, or a whole architecture, such as a website backed by a database and a queue.
The single most important fact about the CDK is that it is a template generator, not a replacement for CloudFormation. When you run cdk synth, the CDK executes your program and emits plain CloudFormation templates into a folder called cdk.out. When you run cdk deploy, it hands those templates to CloudFormation, which computes a change set and provisions the resources. You keep every guarantee CloudFormation gives you — managed rollback, drift detection and an auditable stack — and you lose the hand-written YAML.
CDK supports six languages: TypeScript, JavaScript, Python, Java, C# and Go. TypeScript is the most common choice, because the framework itself is written in TypeScript and its type system catches mistakes at compile time. Python is popular with data and operations teams. The language you choose matters less than the team using it: pick the one your developers already know, because the point of the CDK is to meet developers where they are.
Constructs: the building blocks
A construct is the basic unit of a CDK application, and constructs nest inside each other to form a tree. An app contains stacks, stacks contain constructs, and constructs can contain other constructs. Every construct takes three arguments: a scope (its parent in the tree), an identifier, and optional properties. That tree structure is what lets the CDK generate stable logical identifiers for the resources it creates, and it is also what makes reuse natural: a construct that builds a standard database setup can be instantiated once per environment, or once per service, with different properties each time.
Constructs come in three levels. L1 constructs map one-to-one to CloudFormation resources and carry a Cfn prefix, such as CfnBucket. They expose every property the underlying resource supports, and nothing more. L2 constructs are curated, intent-based wrappers: a bucket construct creates the bucket with sensible defaults, adds helper methods for granting access, and exposes metrics. L3 constructs, also called patterns, combine several resources into an opinionated capability, such as a load-balanced service or a queue-driven worker.
Most day-to-day CDK work uses L2 constructs. They are the sweet spot: expressive enough to describe intent, with defaults that reflect how AWS expects a service to be used. L1 constructs are the escape hatch for anything the curated layer does not yet cover, and L3 patterns are the shortcut when you want a whole architecture in a few lines. Knowing which level you are using matters, because the higher the level, the more the CDK decides on your behalf — which is convenient until you need to understand exactly what will be deployed.

How a CDK application works
A CDK application follows a clear lifecycle. You start with cdk init, which scaffolds a project in your chosen language. Before the first deployment, you run cdk bootstrap, a one-off step that provisions the staging resources the CDK needs in your account and region, such as a storage bucket for deployment assets. After that, the daily loop is short: write constructs, run cdk synth to generate the templates, run cdk diff to compare them with what is already deployed, and run cdk deploy to apply the change.
Synthesis is the step newcomers most often misunderstand. Your CDK code runs during synthesis, not during deployment. That means it must be deterministic and free of side effects: no reading live state, no network calls, no random values. If your code behaves differently each time it runs, the template it produces will differ too, and deployments become unpredictable. Keep infrastructure code boring in that specific way, and the rest of the workflow stays reliable.
Assets are the other concept worth grasping early. When your stack references application code — a function bundle, a container image, a website’s files — the CDK packages those assets during synthesis and uploads them during deployment. This is what makes a CDK project feel unified: the infrastructure and the code it runs live in the same repository, deploy together, and version together. It is also why CDK projects pair so well with the deployment models teams already use for their applications.
Testing and guardrails
Because infrastructure is code, it can be tested like code. The CDK ships an assertions library that lets you write unit tests against the synthesised template: assert that a bucket has encryption enabled, that a queue has a dead-letter queue attached, or that no resource is created without a particular tag. Snapshot tests go further, recording the whole template and failing when it changes unexpectedly, which forces a deliberate review of any drift in what will deploy.
Policy enforcement works at the same level. Aspects let you visit every construct in the tree and apply rules, such as requiring encryption or blocking public access, and community tools such as cdk-nag package common rules into checks you can run in continuous integration. The practical effect is that organisational standards stop being documents people are asked to remember and become checks that fail a build when violated.
None of this replaces reviewing the synthesised template. L2 defaults hide complexity, and a construct that looks like one line of code can expand into dozens of resources. Reading cdk diff output before deploying is the habit that keeps surprises out of production.
CDK compared with the alternatives
The CDK sits between raw CloudFormation and multi-cloud tools. The table below compares the main options so you can see where each one earns its place.
| Approach | How you define infrastructure | Main strength | Main weakness | Best for |
|---|---|---|---|---|
| AWS CDK | TypeScript, Python, Java, C#, Go or JavaScript | Real language features, tests and reusable constructs | AWS only; generated templates can be hard to read | Development teams building on AWS |
| CloudFormation | Declarative YAML or JSON templates | Native, managed, with rollback and drift detection | Verbose; no loops, functions or types | Simple stacks and teams that prefer declarative files |
| Terraform | Declarative configuration in its own language | Multi-cloud and a large provider ecosystem | State management and tooling are your responsibility | Multi-cloud estates and mixed infrastructure |
| CloudFormation plus SAM | Templates with a serverless transform | Concise for serverless applications | Narrow scope beyond serverless workloads | Serverless-first applications on AWS |
Best for: development teams that live on AWS and want infrastructure in the same language, tests and review process as their application code — the CDK is the natural choice, and it deploys through the same CloudFormation engine described in our guide to GitOps practices.
One honest caveat: the CDK’s power is also its risk. A loop that creates one resource per customer, or a construct that quietly provisions an expensive default, can turn a small code change into a large bill. Review diffs, test, and treat infrastructure code with the same care as the application code it supports.
When to use the CDK — and when not to
The CDK fits best when your team writes application code in one of its supported languages, when infrastructure repeats across services or environments, and when you want tests and policy checks on infrastructure changes. It shines in platform teams that build shared constructs — a standard database, a standard API — and hand them to product teams who instantiate them with a few lines. It also fits when your infrastructure logic is genuinely conditional: different resources per environment, per region or per customer tier are all natural in code and painful in YAML.
It fits less well when the team does not write code, when the estate spans multiple clouds, or when the infrastructure is small and stable. A single bucket and a single function do not need a framework, and a team of operators who think in declarative configuration may find Terraform’s language more direct.
Getting started checklist
Use this checklist to set up a CDK project that stays maintainable as it grows.
- Pick the language your team already knows, and pin the CDK library version so upgrades are deliberate.
- Run
cdk bootstraponce per account and region before the first deployment. - Build shared constructs for patterns your team repeats, such as a standard database or API setup.
- Run
cdk synthandcdk diffbefore every deploy, and read the diff before approving it. - Write assertions tests for the properties that matter most, such as encryption, tagging and public access.
- Keep synthesis deterministic: no network calls, live lookups or random values in CDK code.
- Split large applications into multiple stacks with clear boundaries, rather than one giant stack.
- Store the project in version control alongside the application code it deploys.
Frequently asked questions
Does the CDK replace CloudFormation?
No. The CDK generates CloudFormation templates, and CloudFormation provisions the resources. You get the CDK’s expressive authoring on top of CloudFormation’s managed deployment, rollback and drift detection.
Which language should I choose for the CDK?
Choose the language your team already uses for application code. TypeScript is the most common choice and has the most complete library coverage, but Python, Java, C# and Go are all fully supported.
What does cdk bootstrap do?
Bootstrapping provisions the staging resources the CDK needs in an account and region, including a storage bucket for deployment assets. It is a one-off step per account and region, and you repeat it only when the bootstrap template itself changes.
Can I use the CDK with resources I created manually?
Yes, in a limited way. You can import existing resources by their identifiers and reference them from CDK code, but the CDK will not manage their lifecycle unless you bring them under CloudFormation management.
How do I remove everything a CDK app created?
Run cdk destroy. It deletes the stacks the app deployed, subject to the same retention policies as any CloudFormation deletion, so databases with snapshot policies will be preserved rather than destroyed.
Is the CDK free?
The framework itself is open source and free. You pay only for the AWS resources your stacks create, exactly as you would with hand-written CloudFormation templates.







