Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cdk synth with stack name provided still synths all the stacks in the project

This is the app.py

my_env = cdk.Environment(account="XXXXXXX", region="us-east-1")
StackA(app, "stack-a", env=my_env)
StackB(app, "stack-b", env=my_env)

Each of these stacks has a print statement specifying the stack name. When I run this cli command cdk synth StackA, I get the lines below

Inside StackA 
Inside StackB

Why are both stacks sythesizing? How to ignore StackB when I only want StackA to execute?

like image 291
user20358 Avatar asked Nov 27 '25 04:11

user20358


1 Answers

The synth command synthesizes a CloudFormation template from your CDK code, and per CDK docs, it will always run the whole app and generates the template in the cdk.out directory.

synth != deploy, synth will not apply any changes, it will only show the generated CloudFormation template.

When you try to do a synth, cdk will synthesize and generate templates for all of the stacks. Passing the stack name will show the template for only that stack. This behaviour can be verified by doing a cdk synth for a project that has multiple stacks

cdk synth
Successfully synthesized to cdk-cdn/cdk.out
Supply a stack id (all-images, images-cdn) to display its template.
like image 58
Sathyajith Bhat Avatar answered Nov 29 '25 19:11

Sathyajith Bhat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!