sinofseven / serverless-s3-remover

this is plugin of serverless, before "sls remove", this empties the s3 bucket.
MIT License
39 stars 11 forks source link

Please improve error handling for non-existent buckets #15

Open RodneyMarable opened 5 years ago

RodneyMarable commented 5 years ago

If I try to delete a stack with a non-existent bucket present in serverless.yml, serverless-s3-remover doesn't return an accurate error message:

$ aws s3 rb s3://test-bucket-rmarable --force remove_bucket: test-bucket-rmarable

$ aws s3api head-bucket --bucket test-bucket-rmarable An error occurred (404) when calling the HeadBucket operation: Not Found

$ sls remove S3 Remover: Make test-bucket-rmarable empty. Are you sure? [yes/no]: yes S3 Remover: Faild: test-bucket-rmarable may not be empty.

What should happen instead:

$ sls remove S3 Remover: Make test-bucket-rmarable empty. Are you sure? [yes/no]: yes S3 Remover: Faild: test-bucket-rmarable does not exist.

This issue was mentioned in #12 but doesn't seem to have been explicitly addressed.

Thanks for making this very useful plugin available.

ajinabraham commented 4 years ago

Related: https://github.com/sinofseven/serverless-s3-remover/issues/18

coyoteecd commented 3 years ago

@ajinabraham I know it's 2 years after, but for what is worth, I have reimplemented this plugin due to lack of response from maintainer and included a fix for your issue here as well. If the bucket does not exist, you get the following:

serverless-s3-cleaner: my-bucket not found or you do not have permissions, skipping...

Note the message is not 100% accurate because headBucket API call returns 403 if you do not have permissions to the bucket (even if the bucket does not exist). So I did not bother to do it more detailed due to the risk of being misleading.