Skip to content
Latchkey

AWS CDK vs CloudFormation: Code vs Templates

CDK lets you write AWS infrastructure in a real language that synthesizes to CloudFormation; CloudFormation is the underlying template engine itself.

CloudFormation provisions AWS infrastructure from declarative YAML/JSON templates with managed state and change sets. AWS CDK lets you express the same infrastructure in TypeScript, Python, or Java using high-level constructs that synthesize CloudFormation templates - so CDK is a developer layer on top of CloudFormation.

AWS CDKCloudFormation
AuthoringReal languages + constructsYAML / JSON templates
AbstractionHigh (L2/L3 constructs)Raw resources
Under the hoodSynthesizes CFNNative
ReuseFunctions, packages, classesNested stacks, modules
Best forDevelopers wanting code IaCSimple/explicit templates

In CI

CDK reduces boilerplate dramatically - high-level constructs wire up sane defaults - and pipelines treat it as a normal build that runs cdk synth then deploy. Raw CloudFormation is more verbose but fully explicit and has no synth step or language toolchain to manage. Since CDK compiles down to CloudFormation, you can mix them and even drop to raw resources when needed.

Speed it up

Cache CDK language dependencies and run synth/deploy in CI. The synth and deploy run on CI runners; faster managed runners shorten the build.

The verdict

Want code-based IaC with high-level constructs and less boilerplate: AWS CDK. Want explicit templates with no language toolchain: CloudFormation. CDK builds on CloudFormation, so the choice is authoring style.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →