# AWS CDK vs CloudFormation

AWS comparisons · Updated 17 November 2026

**Short answer:** 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.

## When this happens away from your desk

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 CloudConsole app](https://cloudconsole.dev/aws-console-app) · [Download on the App Store](https://apps.apple.com/app/cloudconsole-for-aws/id6835419710)

## Sources

- [What is the AWS CDK?](https://docs.aws.amazon.com/cdk/v2/guide/home.html)
- [AWS CDK bootstrapping](https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping.html)
- [What is CloudFormation?](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)

## Related

- [CloudFormation vs Terraform](https://cloudconsole.dev/vs/cloudformation-vs-terraform)
- [AWS CDK vs Terraform](https://cloudconsole.dev/vs/cdk-vs-terraform)
- [Template format error](https://cloudconsole.dev/errors/cloudformation-template-format-error)
- [Export cannot be deleted as it is in use by another stack](https://cloudconsole.dev/errors/cloudformation-export-in-use)
- [aws cloudformation validate-template](https://cloudconsole.dev/cli/cloudformation-validate-template)
- [ALB vs API Gateway](https://cloudconsole.dev/vs/alb-vs-api-gateway)

---

Source: https://cloudconsole.dev/vs/cdk-vs-cloudformation

CloudConsole is an independent iPhone and Android app for Amazon Web Services by Cloudconcur Ltd. It is not affiliated with Amazon Web Services.
