AWS CDK cost estimation: price the synthesized CloudFormation
CDK synthesizes to CloudFormation, so you estimate cost from the synth output — run cdk synth, then price the templates in cdk.out. Here's how to get a cost per stack before cdk deploy, locally and in CI.
Quick answer
CDK synthesizes to CloudFormation, so estimate cost from the synth output: run cdk synth, then price the templates in cdk.out. You get a per-stack monthly cost before cdk deploy, with no AWS credentials and no stack created. In CI, swap cdk synth for the plan step and gate the build on a budget.
A CDK app hides its resources behind code, loops, conditionals, constructs, and sensible defaults. That's great for authoring and awkward for cost: you can't read the bill off the TypeScript. Synth resolves the app into concrete CloudFormation, and that resolved artifact is what you price.
Estimate the synth output
Run synth and point the estimator at the output directory. The templates in cdk.out are the resolved resources, the same way a Terraform plan is the resolved input on that side.
cdk synth
c3x estimate --path cdk.outPer-stack breakdown
Synth writes one template per stack. Estimating the directory gives a cost per stack plus a combined total, which lines up with how CDK apps are organized, so you see which stack carries the spend, not just the app total.
Fixed vs usage-driven cost
Fixed costs, instances, databases, load balancers, are priced from the synthesized properties. Usage-driven costs depend on traffic: Lambda invocations, S3 requests, NAT data. Give expected volumes to include them; otherwise the estimate is precise on the fixed portion and a modeled range on the variable portion.
In CI
The pattern matches Terraform, with cdk synth instead of terraform plan: synth, estimate cdk.out, comment the cost, and fail the build past a budget. Wire it into GitHub Actions or any CI, and add a budget gate.
CDK, SAM, CloudFormation
All three reduce to CloudFormation, so one estimator covers them: CDK via cdk.out, SAM templates directly, and plain CloudFormation templates as-is. Pick the input your team writes; the pricing is the same.
FAQ
Can I estimate AWS CDK cost before deploying?
Yes. CDK synthesizes to CloudFormation, so you run cdk synth and price the templates it writes to cdk.out. The estimate runs against those templates, not your AWS account, so no credentials are needed and no stack is created.
Why estimate the synth output instead of the TypeScript?
Because the CDK app is code, loops, conditionals, constructs, that only becomes concrete resources after synth. The synthesized CloudFormation is the resolved artifact with the actual resources and properties, which is the accurate thing to price, the same way a Terraform plan beats raw HCL.
Does it handle multiple stacks?
Yes. cdk synth writes one template per stack into cdk.out. Estimate the directory to get a per-stack breakdown and a combined total, which maps cleanly onto how CDK apps are usually organized.
What about usage-based resources like Lambda and S3?
Fixed resource costs are priced from the synthesized properties. Usage-driven costs, Lambda invocations, S3 requests, NAT data, depend on traffic, so provide expected volumes (a usage file) to include them; otherwise the estimate covers the fixed portion precisely and notes the variable portion.
Can I run CDK cost estimation in CI?
Yes. Add a step that runs cdk synth and then prices cdk.out, comment the monthly cost on the PR, and fail the build past a budget. It's the same CI pattern as Terraform, with cdk synth in place of terraform plan.
Does this work for SAM too?
Yes. SAM templates are CloudFormation under the hood, so the same estimator prices them directly. CDK and SAM both reduce to CloudFormation, which is the common input.
What to do next
Run cdk synth and estimate cdk.out to see your app's monthly cost before you deploy. C3X prices the synthesized resources against a live catalog, locally or in CI, with optional budget gating, free and self-hostable. Start with the quickstart.
Share this post
Try C3X on your own Terraform
Free and open source. No API key required. One command to install, one command to estimate.