Skip to content

feat: cdk debootstrap command#952

Draft
sanjanaravikumar-az wants to merge 4 commits into
mainfrom
sanjrkmr/cdk-debootstrap
Draft

feat: cdk debootstrap command#952
sanjanaravikumar-az wants to merge 4 commits into
mainfrom
sanjrkmr/cdk-debootstrap

Conversation

@sanjanaravikumar-az

Copy link
Copy Markdown

This is a request for comments about cdk debootstrap which removes the CDK bootstrap stack and all associated resources from an AWS environment that get created when cdk bootstrap is run.. See #949 for additional details.

APIs are signed off by @{BAR_RAISER}.


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

@sanjanaravikumar-az sanjanaravikumar-az marked this pull request as draft June 19, 2026 21:30
- Wrap lines to stay under 150 character limit
- Add blank lines around lists (MD032)
- Remove multiple consecutive blank lines (MD012)
- Fix table column alignment (MD060)
- Remove trailing spaces (MD009)

##### Usage

When users want to debootstrap a particular account, they run:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: we are writing a user manual. So the person to address here is "you":

When YOU want to remove bootstrap resources from your account, run:

(I also removed the term debootstrap here, because understanding your sentence requires users to learn a new term "debootstrapping" is, and we can fairly easily replace it with just describing what that does)

$ cdk debootstrap aws://123456789012/us-east-1
```

If users want to multi-select environments interactively (discovers bootstrapped

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YOU. Etc...

Comment on lines +47 to +52
1. Empties the S3 staging bucket (all object versions)
2. Deletes all images in the ECR container assets repository
3. Deletes the CDKToolkit CloudFormation stack (which cascades IAM roles, KMS
key, SSM parameter)
4. Deletes the orphaned S3 bucket (left behind due to its
`DeletionPolicy: Retain`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: This is very mechanical of how you're going to achieve the goal. When you are addressing a user, it's usually more interesting to them WHAT the end result is, not HOW you're going to achieve it.

So: all bootstrapped resources, including the asset bucket and ECR repo and all files and images will be deleted. Because the bucket needs to be emptied before it can be deleted, the duration of this operation depends on how many objects are in the bucket.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, what is currently written looks like a procedure for that you will implement - which is more important to something like a technical design. For an RFC, it's OK to omit this level of detail, and focus on the high level. The end user cares more about the interface and the API, rather than the specific implementation steps.

Comment thread text/0949-cdk-debootstrap.md
Comment on lines +99 to +107
##### Idempotency

The command is safe to re-run after partial failure. Each step checks current
state before acting:

- If the stack is already gone but the bucket still exists, it skips to bucket
cleanup
- If the bucket is already empty, it skips to the next step
- If everything is already removed, it exits cleanly

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the point of view of a user, this could be one line:

If the command gets interrupted, you can run it again and it will pick up where it left off.

Comment on lines +211 to +216
2. Match each stack's `RoleARN` field against the pattern
`cdk-${Qualifier}-cfn-exec-role-${Account}-${Region}`
3. Check stack parameters and template body for references to the bootstrap
bucket - `cdk-${Qualifier}-assets-${Account}-${Region}` and ECR repo -
`cdk-${Qualifier}-container-assets-${Account}-${Region}`
4. If there is a match that means that stack depends on this bootstrap

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't do this.

You can get the actual resource names from the actual bootstrap stack stack.

You can then search for ACTUAL resource names in the template, parameters and configuration of all application stacks.

Why is that better?

  • You still catch all the stacks you were planning to catch by looking up predefined names
  • But you also catch the stacks where users customized the stack template and decided to rename the resources.
  • And it's not much more work.

Comment on lines +283 to +286
**`cdk bootstrap --destroy`:** Adds a flag to the existing command. This flag
wouldn't just modify a command's behavior, but invert it. Also,
`cdk bootstrap --destroy --force` is three flags deep and is awkward from a UX
perspective.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with it. It's not like this command is being used every day.

Comment on lines +316 to +317
- **Cross-account notification:** A mechanism to warn trusted accounts when a
bootstrap stack they depend on is about to be destroyed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and aspirational, but I don't think we can do this in practice.

There isn't a good way to "send a message to an account". In this case, I think we just trust the user to understand what they're doing.

Comment on lines +35 to +40
If users want to multi-select environments interactively (discovers bootstrapped
environments and presents a picker):

```console
$ cdk debootstrap
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting choice, as it departs from the convention we use in cdk bootstrap - cdk bootstrap run without parameters inside of a CDK project does the following:

By default, the CDK CLI will bootstrap all environments referenced in the CDK app or will determine an environment from default sources. This could be an environment specified using the --profile option, from environment variables, or default AWS CLI sources.

ref: https://docs.aws.amazon.com/cdk/v2/guide/ref-cli-cmd-bootstrap.html

The RFC suggests an interactive mode, which we don't have for cdk bootstrap. One potential consideration is the use of this command in CI, where interactive mode would create problems.

Not necessarily saying that this needs to change, but flagging as a callout.

Comment on lines +58 to +67
**Prompt 1 - Dependency warning** :

This is shown when there are dependent stacks found.

```
⚠️ The following stacks use this bootstrap and will no longer be deployable or destroyable via CDK:
- MyAppStack
- MyOtherStack

Do you want to continue? (y/N):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this prompt be shown if the user uses --yes?

Are you sure you want to proceed? (y/N):
```

`--force` skips the dependency check entirely. `--yes` skips all interactive

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that this answers my question above. But there is inconsistency in that we indicate "This prompt will always be shown unless the user uses --yes" for prompt 2 and not prompt 1. I recommend consolidating this, maybe just by removing the line I quoted.

Comment on lines +89 to +97
##### Flags

| Flag | Description |
| --- | --- |
| `--force` | Skip the dependency check entirely |
| `--yes` | Skip all interactive prompts (global flag) |
| `--qualifier` | Target a non-default bootstrap stack (default: `hnb659fds`) |
| `--toolkit-stack-name` | Override the default stack name `CDKToolkit` |
| `--profile` | AWS named profile to use |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any non-interactive mode?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe have an -i flag (--interactive option), or something like that, if offering interactive mode.

Comment on lines +181 to +183
This risk is mitigated by the dependency detection warning and the two
confirmation prompts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also bootstrap again, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants