Steps
run 'cdk bootstrap' creates S3 Bootstrap Bucket via cloudformation template.
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.
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 thecdk 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.
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
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
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:
And: