AWS CDK vs CloudFormation
The CDK is not an alternative engine: it generates CloudFormation templates from code and deploys them as stacks. Use the CDK when you build and maintain many resources and want constructs, loops, types and unit tests. Use plain CloudFormation (or AWS SAM) for small, stable templates, for StackSets and Service Catalog products, or when the people maintaining it do not write code.
CDK vs CloudFormation compared
| Factor | AWS CDK | CloudFormation templates |
|---|---|---|
| Authoring | TypeScript, JavaScript, Python, Java, C#/.NET or Go | YAML or JSON |
| Output | Synthesised CloudFormation template plus assets | The template itself |
| Abstraction | L2/L3 constructs with defaults and grant helpers | One resource at a time; modules and macros for reuse |
| Assets | Bundles Lambda code and Docker images automatically | You package and upload them (or use aws cloudformation package) |
| Prerequisites | Bootstrap per account and Region; Node.js for the CLI | None |
| Preview | cdk diff | Change sets |
| Deployment, state, rollback | CloudFormation | CloudFormation |
| Cost | Same as CloudFormation | No charge for AWS resource types |
When the CDK is worth it
- Many similar services or environments: a construct encodes the pattern once.
- You want IAM policies derived from relationships (
table.grantReadWriteData(fn)) rather than written by hand. - Lambda and container assets built and uploaded as part of
cdk deploy. - Infrastructure unit tests with assertions on the synthesised template.
Every CloudFormation resource is available as an L1 construct (named Cfn...), generated from the CloudFormation specification; new resources or properties can take up to a week to appear in the construct library. Escape hatches let you override any property on a higher-level construct.
When plain CloudFormation is better
- A small, rarely changing stack: a few IAM roles, a bucket, an alarm.
- Templates distributed to other teams or accounts through StackSets, Service Catalog or the console, where a readable template is the product.
- Teams without a language toolchain in the pipeline, or a strict rule against generated templates.
- Serverless apps where AWS SAM's short syntax is enough.
Moving between them
To adopt the CDK without redeploying, wrap an existing template with CfnInclude and refactor gradually; logical IDs stay the same so CloudFormation sees no replacement. To leave the CDK, run cdk synth and keep the generated template, though it will be harder to read than hand-written YAML. Avoid changing construct IDs during refactors: a changed logical ID means CloudFormation replaces the resource, which for a database or bucket can mean data loss unless it is retained.
Common wrong reasons
- "The CDK removes CloudFormation's limits." Templates still have resource, parameter and output quotas, and deployments still go through stacks.
- "CDK deploys faster." The deploy is CloudFormation either way; only authoring is faster.
- "CloudFormation cannot reuse code." Modules, nested stacks and macros exist, though the CDK makes reuse easier.
Questions
Is the AWS CDK the same as CloudFormation?
No, but it uses it. The CDK is a framework that synthesises CloudFormation templates from code; CloudFormation then deploys and tracks the resources.
What is cdk bootstrap?
A one-time setup per account and Region that deploys a CloudFormation stack with an S3 bucket, an ECR repository and IAM roles the CDK uses to deploy.
Can I convert a CloudFormation template to CDK?
Yes. Use CfnInclude to import the template into a CDK app as-is, then refactor resources into higher-level constructs over time.
Whether the template came from CDK or YAML, a stuck rollback is debugged from stack events. CloudConsole is being built to show stack events and related alarms on a phone with production guardrails.
About the app → · Download on the App Store