Is it somehow possible to get a list of the stacks that another stack depends on using the AWS CDK CLI? For example, given a list of stacks that looks something like:
const app = new App();
const alphaStack = new Stack(app);
const betaStack = new Stack(app);
betaStack.addDependency(alphaStack);
const gammaStack = new Stack(app);
gammaStack.addDependency(gammaStack);
const deltaStack = new Stack(app);
deltaStack.addDependency(betaStack);
deltaStack.addDependency(gammaStack);
I'd like to run a command that could give me output similar to the following:
$ cdk list-deps alpha-stack # no result
$ cdk list-deps beta-stack
alpha-stack
$ cdk list-deps gamma-stack
alpha-stack
$ cdk list-deps delta-stack
beta-stack
gamma-stack
Specifically, I'd like to be able to run this before I deploy my stacks.
In case this helps anyone in the future; the following seems to solve the problem that I wanted to solve:
// the stack that we're interested in finding deps for
const stackName = "...";
// assuming app is as defined in the question
const { stacks } = app.synth();
stacks
.find(({ stackName }) => stackName === searchForStackName)
?.dependencies.forEach((dep) => console.log(dep.id));
Caveats:
app from your CDK definitions.synth on the app. Initially my understanding was that this creates some artifacts within AWS, which I wanted to avoid; but it seems that's not actually the case.dep.id is from this snippet/answer. Although it has so far been robust enough for my purposes, dependencies returns a list of CloudArtifact which I'm not certain if it will always represent a Stack.