Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 bucket default removal policy not respected #2526

Closed
thesurlydev opened this issue May 11, 2019 · 4 comments
Closed

S3 bucket default removal policy not respected #2526

thesurlydev opened this issue May 11, 2019 · 4 comments
Labels
bug This issue is a bug. closing-soon This issue will automatically close in 4 days unless further comments are made.

Comments

@thesurlydev
Copy link
Contributor

thesurlydev commented May 11, 2019

Describe the bug
Documentation states that the RemovalPolicy.Destroy is the default but if you don't explicitly set the value, the S3 bucket will not be removed on cdk destroy.

To Reproduce
The following code will not destroy the S3 bucket:

val buildBucket = Bucket(this, "buildbucket", BucketProps.builder()
            .withBucketName(props.buildBucketName)
            .build()
        )

However, explicitly setting RemovalPolicy will destroy the bucket during cdk destroy:

val buildBucket = Bucket(this, "buildbucket", BucketProps.builder()
            .withBucketName(props.buildBucketName)
            .withRemovalPolicy(RemovalPolicy.Destroy)
            .build()
        )

Expected behavior
S3 bucket should be destroyed without explicitly defining removal policy.

Version:

  • Ubuntu
  • Java/Kotlin
  • 0.31.0
@thesurlydev thesurlydev added the bug This issue is a bug. label May 11, 2019
@schof
Copy link
Contributor

schof commented May 15, 2019

If there are any files in the bucket, Cloudformation will not delete the S3 bucket, no matter what you say or how you ask. In other words, this is not a CDK-specific issue.

I agree this is a PITA which is why I created AutoDeleteBucket which will do what you want.

Protip: You can specify anAutoDeleteBucket anywhere can use Bucket which allows you to automatically delete buckets associated with codepipeline, etc.

@thesurlydev
Copy link
Contributor Author

@schof I understand bucket deletion is not allowed if it's not empty but that's not the case here.

At the very least, the documentation should be updated or behavior changed to match what the docs say.

@RomainMuller
Copy link
Contributor

The documentation fairly unambiguously states that the default behavior for s3.BucketProps.removalPolicy is to orphan the bucket.

@RomainMuller RomainMuller added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jun 21, 2019
@nija-at
Copy link
Contributor

nija-at commented Aug 21, 2019

As stated in #3297, this will either be supported by Cloudformation or to incorporate force deletion of S3 buckets into CDK as custom resource.

Recommend continuing the conversation at #3297. Closing this issue.

@nija-at nija-at closed this as completed Aug 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. closing-soon This issue will automatically close in 4 days unless further comments are made.
Projects
None yet
Development

No branches or pull requests

4 participants