Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(aws-cdk): (Unable to create nested stack with > 500 resources) #28186

Closed
benliger1987 opened this issue Nov 29, 2023 · 9 comments
Closed

(aws-cdk): (Unable to create nested stack with > 500 resources) #28186

benliger1987 opened this issue Nov 29, 2023 · 9 comments
Assignees
Labels
bug This issue is a bug. effort/small Small work item – less than a day of effort p1 package/tools Related to AWS CDK Tools or CLI

Comments

@benliger1987
Copy link

Describe the bug

I am using a nested stack inside of a regular stack to get past the resource limit of 500 in a stack. After moving 413 resources to a nested stack I receive the following error on deployment:

[Info at /dev/Frontend/LambdasApi-dev] Number of resources: 413 is approaching allowed maximum of 500

Please note that /dev/Frontend/LambdasApi-dev refers to my nested stack.

As per the resource limits stated in this table here:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html

Nested stacks should have a max resource limit of 2500, not 500 hence the bug.

The part of the repository that gives this warning is here, the nested stack class simply extends the stack with some modifications, resource limit is not one of those modifications:

Annotations.of(this).addInfo(`Number of resources: ${numberOfResources} is approaching allowed maximum of ${this.maxResources}`);

Expected Behavior

I would expect to be able to create 2500 resources in a nested stack as per the documentation here:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html

Current Behavior

I receive a warning message if I am close to going over 500 resources in a nested stack and presumably an error if I do go over 500

Reproduction Steps

  1. Create a stack
  2. Create a nested stack within the first stack
  3. Populate the nested stack with >400 resources to receive the warning and >500 to presumably get an error

Possible Solution

Implement custom resource limits for Nested Stacks

Additional Information/Context

No response

CDK CLI Version

2.111.0

Framework Version

No response

Node.js Version

18.16.0

OS

Ubuntu

Language

TypeScript

Language Version

No response

Other information

No response

@benliger1987 benliger1987 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 29, 2023
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Nov 29, 2023
@benliger1987 benliger1987 changed the title (aws-cdk): (short issue description) (aws-cdk): (Unable to create nested stack with > 500 resources) Nov 29, 2023
@pahud pahud self-assigned this Nov 29, 2023
@pahud
Copy link
Contributor

pahud commented Nov 29, 2023

@pahud pahud removed their assignment Nov 29, 2023
@pahud pahud added effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. needs-review labels Nov 29, 2023
@scanlonp scanlonp self-assigned this Nov 30, 2023
@scanlonp
Copy link
Contributor

Hi @benliger1987, in my mind, there is a difference between a nested stack and a child stack. The nested stack is the entire structure, which is made up of parent and child stacks, similar to a tree vs nodes. It does not seem plausible that just because a single stack is a child stack, that its resource limit jumps from 500 to 2500. I believe the 2500 limit is the sum of all the child stack's resources in the entire nested structure. (Otherwise this somewhat unbounds the resource limit.)

Was this your understanding too? If so this may well be a bug.

If not, your solution could be to split the stack that is approaching the individual stack limit into smaller stacks.

In any case, the documentation is ambiguous and should be clarified.

@benliger1987
Copy link
Author

Im not sure what you're referring to by child stacks? There are only regular stacks and nested stacks no?

@scanlonp
Copy link
Contributor

scanlonp commented Dec 4, 2023

My mental model does not have quite the same terminology as the documentation, apologies. Going off this page (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-nested-stacks.html), I see that what I was calling "child stacks" are "nested stacks". You are correct.

After re-reading both documentation pages, I saw that the Resources row in the Quotas column states Maximum number of resources that you can declare in your AWS CloudFormation template is 500 resources. This says to me that in any one stack template, 500 resources is the hard cap.
However, nested stacks can operate on (create, update, or delete) up to 2500 resources.

So I think the error message you are getting is correct. A nested stack could create up to 2500 resources per operation, but they will not be in a single template.

@benliger1987
Copy link
Author

I kind of see where you're getting at but not sure I fully follow your rationale. Would someone from AWS perhaps be able to weigh in here?

@scanlonp
Copy link
Contributor

scanlonp commented Dec 6, 2023

I am at AWS! But I can see if someone with cloudformation specific domain knowledge has any context. However, I see the 500 resource limit per template as clear cut.

@azhong-git
Copy link

Following the unblock advice from #28186 (comment) to set "@aws-cdk/core:stackResourceLimit": 0 in cdk.json.

However I am seeing the following error. What is the actual maximum number of resources?

 [ValidationError]: Template format error: Number of resources, 502, is greater than maximum allowed, 500

@TheRealAmazonKendra
Copy link
Contributor

@scanlonp's assessment is correct here. Each stack, nested or otherwise, can only have up to 500 resources each. If you are performing some operation on the entire set of nested stacks within your stack hierarchy, you can perform that operation on up to 2500 resources at a time.

So, you could have five stacks with 500 resources each in your stack hierarchy, or any other combination that is within that limit. See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-nested-stacks.html for more details.

Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. effort/small Small work item – less than a day of effort p1 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants