Skip to content

feat(toolkit-lib): explain the CloudFormation resources per operation quota error - #2196

Open
DiegoOrtizS wants to merge 1 commit into
aws:mainfrom
DiegoOrtizS:feat/explain-nested-stack-quota-error
Open

DiegoOrtizS wants to merge 1 commit into
aws:mainfrom
DiegoOrtizS:feat/explain-nested-stack-quota-error

Conversation

@DiegoOrtizS

@DiegoOrtizS DiegoOrtizS commented Dec 2, 2026 •

Copy link
Copy Markdown

Closes #2191

Since #1531, the change sets that cdk deploy creates include nested stacks. When a deployment changes more than 2,500 resources across a nested stack hierarchy, change set creation fails like this:

Failed to create change set cdk-deploy-change-set-Child5NestedStackChild5NestedStackResource52CF403C-QQ2G3WYQHGI:
NestedQuotaRepro/Child5.NestedStack/Child5.NestedStackResource  (AWS::CloudFormation::Stack)
  Limit on the number of resources in a single stack operation exceeded

The error names a single nested stack, so it reads like a problem with that stack, and nothing points at the fix. In #2191 we read it as a regression from #1531, and #2195 proposed --no-include-nested-stacks to opt out of nested change sets. This PR replaces #2195.

What testing showed

I deployed a synthetic hierarchy in my own account: a root stack with 6 nested stacks of 450 AWS::CloudFormation::WaitConditionHandle each, 2,706 resources in total.

Deployment Nested change sets Result
Add 902 resources (1,804 → 2,706) yes (default) succeeds
Change 1 resource yes (default) succeeds
Change 1 resource no (--no-include-nested-stacks) succeeds
Change 2,600 resources yes (default) change set creation fails with the quota error
Change 2,600 resources no (--no-include-nested-stacks) change set is created, then execution fails with the same error and every nested stack rolls back

So the quota counts the resources that a deployment changes, whether or not the change set includes nested stacks. Including them only makes CloudFormation report the problem before anything is touched. The opt-out would have turned a fast failure into a slow one with a rollback, so I closed #2195. Our failure came from an aws-cdk-lib upgrade that changed more than 2,500 resources at once.

Change

This PR explains the error instead. When a change set fails with this quota error, the diagnosis now adds:

   A deployment of a stack with nested stacks can create, update or delete at most 2,500 resources, and this deployment changes more.
   The quota applies to the whole stack hierarchy, not only to the nested stack named above.
   Split the change into several smaller deployments.
   Quotas: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html
  • toolkit-lib: a new explainKnownError in lib/api/diagnosing/known-errors.ts, called from enhanceError in the stack diagnoser. It returns additionalContext, so cdk diagnose and toolkit-lib consumers get the same context through the existing StackDiagnosis type, with no public API change.
  • README: a note in the change set section about the quota and how to split the deployment.

Design notes

  • The match is on CloudFormation's message text, because the error has no code. If CloudFormation changes the wording, the hint stops showing and nothing else changes.
  • The module handles one error for now. It's a single place to add more known errors later.
  • Out of scope: when the quota is hit during execution rather than at change set creation, CloudFormation reports it only in events of AWS::CloudFormation::Stack resources, which the diagnoser skips on purpose (isRegularResourceEvent). Changing that would affect every nested stack failure, so I left it for a separate discussion.

Testing

  • Unit tests for explainKnownError, plus diagnoser tests that a failed nested change set with this error gets the context (including the thrown DeploymentError message) and that other nested change set failures don't.
  • Ran the CLI built from this branch against the hierarchy above. The 2,600-resource change failed at change set creation with the output shown in this description, and the test stacks were deleted afterwards.

Checklist

  • This change contains a major version upgrade for a dependency and I confirm all breaking changes are addressed
    • Release notes for the new version:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

🤖 Generated with Claude Code

… quota error

Since aws#1531, deploy change sets include nested stacks. When a deployment
changes more than 2,500 resources across a nested stack hierarchy,
change set creation fails with "Limit on the number of resources in a
single stack operation exceeded". The error names a single nested stack,
so it reads like a problem with that stack and gives no hint at the fix.

Add context to the diagnosis saying the quota covers the whole stack
hierarchy and that the change must be split into smaller deployments,
and document the quota in the README.

Closes aws#2191

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch is waiting to be deployed

1 active and 1 waiting deployments
integ-approval — 007c646f Waiting Dec 2, 2026 by DiegoOrtizS via prepare #7832
automation — 007c646f Deployed Dec 2, 2026 by DiegoOrtizS via Set AutoQueue on PR #2196 #4071
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

1 participant