I'm trying to deploy a quite big stack using CDK TypeScript. When I ran cdk deploy myApp
, I got Template format error: Number of resources, 257, is greater than maximum allowed, 200
error.
After some research, I think I know what's the issue. From the docs:
The keyword here is "nested stacks" and that's what I'm planning to do now. From my reading, I'm clear what I'm suppose to do in terms of creating parent and nested stacks.
The question here is, is there any available TS function in CDK library that I can call to tell me how many resources that a stack will generate?
Or, in simpler words, I want the TS function to tell me "with all these declarations defined in this stack, you will create xxx number of resources under this stack".
Even better, a TS function that can list all resources that will be generated under the stack.
I'm looking for something like this:
new cdk.CfnOutput(this, "TotalResources", {
value: ___, // <-- any idea what's available for this one?
});
With this helper function, it will help me with my refactoring and nested stacks planning work.
Including this in CDK is tricky, because you'll have to resolve this count when you've completed your stack.
Why don't you just run cdk -j synth | jq '.Resources | length'
to get the number of resources?
cdk -j synth | jq '.Resources | length'
will work if you are deploying a single stack.
cdk -j synth YOUR_STACK_NAME_HERE | jq '.Resources | length'
if you have multiple stacks.