Aws-cdk: cdk bootstrap - no destroy option

Created on 22 Oct 2018  ·  15Comments  ·  Source: aws/aws-cdk

Steps

  1. run 'cdk bootstrap' creates S3 Bootstrap Bucket via cloudformation template.

  2. run 'cdk bootstrap destroy' or 'cdk destroy'

Expected:
Informs you you need to remove the bootstrap bucket manually and then delete the cloudformation. (perhaps also the name and region with links)
Or : Removes the cloudformation S3 bucket , which could get below error.
-----The bucket you tried to delete is not empty (Service: Amazon S3; Status Code: 409; Error Code: BucketNotEmpty; Request ID:
Or: Option to delete the s3 bucket if empty

Current: S3 bucket not removed or no option to run.

Workaround:
Open console our use CLI to remove the s3 bucket created and the cloudformatin template

Note: Is it a standard use case to always run cdk bootstrap before initial deploy.

efformedium feature-request p1 packagtools

Most helpful comment

I think there are use cases where people want to destroy the bootstrap stack, let alone cleaning the bucket up. Technically those buckets can fill up quite easily and incur unwanted costs for users.

I think we should support something like:

$ cdk bootstrap --destroy

And:

$ cdk boostrap --clean

All 15 comments

The standard practice would be to run cdk bootstrap once per account/region pair you want to deploy CDK stuff into (using cdk deploy). You shouldn't need to destroy this ever (but I reckon you can if you don't intend on using the CDK anymore, or are not using the CDK toolkit for deployment).

I think there are use cases where people want to destroy the bootstrap stack, let alone cleaning the bucket up. Technically those buckets can fill up quite easily and incur unwanted costs for users.

I think we should support something like:

$ cdk bootstrap --destroy

And:

$ cdk boostrap --clean

Is it a standard use case to always run cdk bootstrap before initial deploy.

As far as I know, if a template size is bigger than 50KB, cdk bootstrap turns into an essential step in order to upload the template to S3.

Is it enough to just destroy the CloudFormation stack CDKToolkit that was created by the cdk bootstrap command as a measure to reverse the operation?

This is also useful, for anyone who landed here: https://github.com/aws/aws-cdk/issues/1812#issuecomment-465983177

Is it enough to just destroy the CloudFormation stack CDK Toolkit that was created by the cdk bootstrap command as a measure to reverse the operation

IIRC, If the bucket is non-empty, then the CloudFormation delete step will skip it. Only empty buckets can be deleted by destroying the stack.

Is it planned to add a delete command for this or are we just relying on the user deleting the CDKToolkit stack? Just out of curiosity

Just ran into this issue. i had a frontend that failed to deploy. part of that frontend deployment was a bunch of s3 buckets. i accidentally deleted the cdk staging bucket and got stuck not being able to do anything. would make total sense to be able to delete the bootstrap.

Thanks to this thread i was able to go into CloudFormation and delete the CDKToolkit template (otherwise I would have no idea) and then re-run cdk bootstrap after that. However, I agree it should be an option in the cli.

It is important to be able to un-bootstrap for the sakes of testing everything from 0 to 100%.

To clean up fast now:

aws cloudformation delete-stack --stack-name CDKToolkit
aws s3 ls | grep cdktoolkit # copy the name
aws s3 rb --force s3://cdktoolkit-stagingbucket-abcdef # replace the name here

Edit: added --force. Thanks to https://github.com/aws/aws-cdk/issues/986#issuecomment-683700877

I have been trying out cdk and I am really bad at naming. I named everything test. Now when I read cloudformation template I can't tell what is meaning of each test. But I was able to try out everything.

Now I would like to destory bootstrap s3 bucket and there is no option. Other than manual nuclear force delete.

@RomainMuller

The standard practice would be to run cdk bootstrap once per account/region pair you want to deploy CDK stuff into (using cdk deploy). You shouldn't need to destroy this ever (but I reckon you can if you don't intend on using the CDK anymore, or are not using the CDK toolkit for deployment).

Also within same account and within same region I plan to launch multiple project and I don't want to mix all of them into single cdk project. I want each project to have their own independant cdk project.

PLEASE HELP

I manually deleted cdktoolkit-stagingbucket-xxx and now I tried to create another project and deploy.

Its successfully bootstrapping but it fails to deploy with following error.

[100%] fail: No bucket named 'cdktoolkit-stagingbucket-xxx'. Is account {account#} bootstrapped?

And here is when I cdk bootsrap again.

 ⏳  Bootstrapping environment aws://{account#}/eu-west-1...
 ✅  Environment aws://{account#}/eu-west-1 bootstrapped (no changes).

Again when I deploy it fails with error above

Solved

Just delete CDKToolkit named cloudformation stack from that region and bootstrap again. It worked.
Never going to manually delete anything. I almost got locked out of region for CDK.

It is important to be able to un-bootstrap for the sakes of testing everything from 0 to 100%.

To clean up fast now:

aws cloudformation delete-stack --stack-name CDKToolkit
aws s3 ls | grep cdktoolkit # copy the name
aws s3 rb s3://cdktoolkit-stagingbucket-abcdef # replace the name here

Thank you for this snippet! 👍
I needed to add --force to the last command to allow the deletion of a non empty s3 bucket.

Thanks @0xVesion for the correction. I edited my original comment to add the --force

I couldn't successfully delete the CDKToolkit stack until the staging bucket was emptied. Building on earlier comments from @moltar and @0xVesion, I use:

bash cdk destroy aws s3 rm --recursive s3://$(aws s3 ls | grep cdktoolkit | cut -d' ' -f3) # empty the cdktoolkit staging bucket aws cloudformation delete-stack --stack-name CDKToolkit

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eladb picture eladb  ·  33Comments

AlexCheema picture AlexCheema  ·  32Comments

eladb picture eladb  ·  52Comments

markusl picture markusl  ·  37Comments

jaapvanblaaderen picture jaapvanblaaderen  ·  27Comments