Describe the feature
cdk refactor should respect a custom toolkit stack name (from --toolkit-stack-name or the toolkitStackName setting in cdk.json) when it looks up the bootstrap stack.
Use Case
When refactoring stacks whose templates exceed the 50KiB limit, the refactor action must upload templates to the bootstrap staging bucket. To find that bucket, the large-template path in @aws-cdk/toolkit-lib (lib/api/refactoring/stack-definitions.ts) constructs new EnvironmentResourcesRegistry() without a toolkit stack name, so ToolkitInfo.lookup() always falls back to the default CDKToolkit name. The CLI side compounds this: cli.refactor(...) in packages/aws-cdk/lib/cli/cli.ts does not forward the resolved toolkitStackName (unlike deploy/import, which thread it through Deployments).
As a result, any environment bootstrapped under a custom toolkit stack name fails large-template refactors with:
Refactor failed: Template too large to refactor ("cdk bootstrap" is required)
even though the environment is correctly bootstrapped.
We hit this in the CLI integration tests while moving them to randomly-qualified, custom-named bootstrap stacks (#1789), but it affects any customer using --toolkit-stack-name / toolkitStackName.
Proposed Solution
Thread the toolkit stack name through the refactor action:
- Add it to the refactor options in
@aws-cdk/toolkit-lib and pass it to EnvironmentResourcesRegistry in stack-definitions.ts.
- Forward the already-resolved
toolkitStackName in the CLI's case 'refactor' handler.
Other Information
No response
Acknowledgements
CDK CLI Version
2.1134.0
Environment details (OS name and version, etc.)
CI (GitHub Actions, cli-integ tests)
This issue was filed by an AI agent (Kiro) on behalf of @mrgrain.
Describe the feature
cdk refactorshould respect a custom toolkit stack name (from--toolkit-stack-nameor thetoolkitStackNamesetting incdk.json) when it looks up the bootstrap stack.Use Case
When refactoring stacks whose templates exceed the 50KiB limit, the refactor action must upload templates to the bootstrap staging bucket. To find that bucket, the large-template path in
@aws-cdk/toolkit-lib(lib/api/refactoring/stack-definitions.ts) constructsnew EnvironmentResourcesRegistry()without a toolkit stack name, soToolkitInfo.lookup()always falls back to the defaultCDKToolkitname. The CLI side compounds this:cli.refactor(...)inpackages/aws-cdk/lib/cli/cli.tsdoes not forward the resolvedtoolkitStackName(unlike deploy/import, which thread it throughDeployments).As a result, any environment bootstrapped under a custom toolkit stack name fails large-template refactors with:
even though the environment is correctly bootstrapped.
We hit this in the CLI integration tests while moving them to randomly-qualified, custom-named bootstrap stacks (#1789), but it affects any customer using
--toolkit-stack-name/toolkitStackName.Proposed Solution
Thread the toolkit stack name through the refactor action:
@aws-cdk/toolkit-liband pass it toEnvironmentResourcesRegistryinstack-definitions.ts.toolkitStackNamein the CLI'scase 'refactor'handler.Other Information
No response
Acknowledgements
CDK CLI Version
2.1134.0
Environment details (OS name and version, etc.)
CI (GitHub Actions, cli-integ tests)
This issue was filed by an AI agent (Kiro) on behalf of @mrgrain.