Skip to content

refactor: does not respect custom toolkit stack name when uploading large templates #1790

Description

@mrgrain

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

  • I may be able to implement this feature request
  • This feature might incur a breaking change

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions