This script is conceptually based on s3nuke but with an entirely different implementation. The key differences are:
- Uses deleteObjects to delete in batches rather than calling a delete for each key.
- Is implemented in node to take advantage of it's evented IO
On my office connection I can delete about 50,000 objects per minute. Since each batch is two queries (one to get the list and one to request the delete) it generally is deleting about as fast as it can know about the files. This means the completion rate generally hovers around 100% (making the progress bar and remaining time somewhat meaningless).
The following environment variables are used for access and to know what bucket to operate on:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- S3_BUCKET
In addition the script takes an optional command line argument that limits the deletion to just the given value as a key prefix. To make it easier to run you can create a .env
file with the environment variables using the standard dotenv convention.
Copy the files in this gist to a directory and run:
npm install
This will download and install the dependencies. Next you need to convert the coffeescript to JS.
coffee -c s3nuke-node.coffee
This assumes you have both npm, node and coffeescript installed.
Once installed setup a .env
file with your credentials and the bucket you want to clear. Then run:
node s3nuke-node.js my-folder
The argument is optional. Leave it off to delete the entire bucket contents. On some systems the command
will be nodejs
instead of node
.
Occasionally S3 will return a random error. This is normal. It will kill the script but you can just restart.