aws-cdk: cli: cdk synth doesn't output yaml when having dependency stacks
❓ General Issue
I have a LambdaStack depending on NetworkStack’s vpc. There is the code
LambdaStack
import cdk = require('@aws-cdk/core');
import lambda = require('@aws-cdk/aws-lambda');
import iam = require('@aws-cdk/aws-iam');
import vpc = require('@aws-cdk/aws-ec2')
interface LambdaStackProps extends cdk.StackProps {
vpc: vpc.Vpc
}
export class LambdaStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props: LambdaStackProps) {
super(scope, id, props);
// define lambdas by using props.vpc
}
}
NetworkStack
import cdk = require('@aws-cdk/core');
import ec2 = require("@aws-cdk/aws-ec2");
import iam = require("@aws-cdk/aws-iam");
interface NetworkStackProps extends cdk.StackProps { }
export class NetworkStack extends cdk.Stack {
public readonly vpc: ec2.Vpc;
constructor(scope: cdk.Construct, id: string, prop: NetworkStackProps) {
super(scope, id, prop);
this.vpc = new ec2.Vpc(some code here);
}
}
app
const networkStack = new NetworkStack(app, 'network-stack-dev', { env: UsEast1Env });
const lambdaStack = new LambdaStack(app, 'lambda-stack-dev', {
env: UsEast1Env,
vpc: networkStack.vpc
});
I tried to generate yaml file for LambdaStack by executing
cdk synth lambda-stack-dev > template.yaml
Then I got
Including dependency stacks: network-stack-dev
Successfully synthesized to /Users/whao/Developer/serverless-dev/cdk.out
Supply a stack name (network-stack-dev, lambda-stack-dev) to display its template.
I tried cdk synth network-stack-dev lambda-stack-dev but it gave the same output. I am kinda confused with what Supply a stack name (network-stack-dev, lambda-stack-dev) to display its template. means
I have read issue #3259 but I didn’t find it helpful. Forgive me if I am asking stupid questions.
Environment
- CDK CLI Version: 1.4.0 (build 175471f)
- Module Version: N/A
- OS: macOS 10.14.6
- Language: TypeScript
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 28
- Comments: 20 (6 by maintainers)
Commits related to this issue
- fix(cli) cdk synth doesn't output yaml for explicitly specified stacks that have dependency stacks fixes #3721 — committed to madeline-k/aws-cdk by madeline-k 3 years ago
- fix(cli): cdk synth doesn't output yaml for stacks with dependency stacks (#14805) * fix(cli) cdk synth doesn't output yaml for explicitly specified stacks that have dependency stacks fixes #3721 ... — committed to aws/aws-cdk by madeline-k 3 years ago
- fix(cli): cdk synth doesn't output yaml for stacks with dependency stacks (#14805) * fix(cli) cdk synth doesn't output yaml for explicitly specified stacks that have dependency stacks fixes #3721 ... — committed to hollanddd/aws-cdk by madeline-k 3 years ago
@sacag I was struggling with this myself and I found that if I added the
--exclusively, -eflag to thesynthcommand, I could get it to generate the YAML for the dependent stack. Hope that helps.bumping this up as a
p1to prioritize a fixWe’re still seeing this issue in 1.19.0 - what’s the likelihood of it being picked up? It’d be great to be able to synth stacks without relying on
cdk.outand having to convert the generated json into yaml for readabilityEDIT: After looking through the code in
aws-cdk, it appears that what’s happening is upstream stacks are being synthesized too, even if you specify a particular stack. Adding the-eflag setsexclusivelyto true, and only synthesizes the specified stack. It’s not clear from the docs that the list of stacks to synthesize is also the list of stacks it tries to print, so if there’s a dependency, it’ll try to synthesize those also, and fail to print to stdout because there are more than one.I’d suggest updating the printed text on
packages/aws-cdk/bin/cdk.ts:334to suggest that-emight help if there are dependencies.+1
put the hack code at the end of app.ts can generate all yaml files in cdk.out:
Hello @nija-at - do you know if there is a solution to generate YAML for dependent stacks?
@dabarrell - thanks for the suggestion! We’ll change for this to explain this better.
Also, we’re fairly good at reviewing and accepting pull requests, in case you’d like to help us out.
As a workaround, both the synthesized stack is present in the
cdk.outfolder in JSON format. That should unblock anyone who wants to find the synthesized stacks.@jayrmotta - the issue you’re pointing out is being tracked in #3705. This one is about
cdk synthnot producing the expected synthesized yaml.