Serverless Framework plugin that empties an S3 bucket before removing a deployed stack. Replacement for serverless-s3-remover which is no longer maintained.
npm install serverless-s3-cleaner --save-devVersion 1.0.2 is compatible with Serverless Framework v3, but it uses the legacy logging interface. Version 2.0.0 and later uses the new logging interface.
| serverless-s3-cleaner | Serverless Framework |
|---|---|
| ≤ v1.0.1 | v1.x, v2.x |
| v1.0.2 | v1.x, v2.x, v3.x |
| ≥ v2.0.0 | v3.x |
Add the following to your serverless.yml:
plugins:
- serverless-s3-cleaner
custom:
serverless-s3-cleaner:
# (optional) Whether to prompt before emptying a bucket. Default is 'false'.
prompt: false
# Names of buckets to remove before a stack is removed, or via 'sls s3remove' command
buckets:
- bucketName1
- bucketName2
# (optional) Buckets to remove before a stack is deployed.
bucketsToCleanOnDeploy:
- oldBucketNameWhen removing a Serverless Framework stack, this plugin automatically empties the buckets listed under buckets option.
When deploying a Serverless Framework stack, this plugin automatically empties the buckets listed under bucketsToCleanOnDeploy option.
Use this when renaming or removing a bucket (put here the old bucket name) to avoid deployment errors when CloudFormation tries to remove the old bucket.
You can also empty a bucket explicitly by running:
sls s3removeBuckets with versioning enabled are supported. When emptying a bucket, all object versions and delete markers are deleted.
The plugin requires the following permissions to be given to the role that Serverless runs under, for all the affected buckets:
- s3:ListBucket
- s3:ListBucketVersions
- s3:DeleteObject
- s3:DeleteObjectVersion