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?
CodePudding user response:
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.