A CLI utility to nuke all the files and all versions from an S3 Bucket rapidly by utilizing both concurrency and bulk API calls to AWS.
- By utilizing concurrency and bulk API calls, s3-nuke is fast at what it does!
- Auto-detect S3 bucket region -- no need to figure out what region the bucket is in before hand!
- Text-based UI makes it easy to select your target bucket!
- S3-Nuke includes safety prompts to ensure you REALLY want to nuke everything in a bucket! After all, the operation is not reversible since you are removing all the object versions as well!
- Includes extra tooling to give you a quick look at bucket metrics (
s3-metrics
) or generate test buckets with data (s3-gen
)
...because deleting any bucket with files is just plain annoying.
There have been so many times when I've needed to delete a bucket, but AWS won't let you because the bucket isn't empty. Emptying the bucket isn't a trivial task when it has, for example, been in production for years and has millions of objects inside. Using the AWS console's "Empty Bucket" isn't an option because it's horribly slow and prone to failure.
While there are several other scripts and projects that do the same function, I wanted something with a little more interactivity. (Also, I was bored 😊)
S3-Nuke requires S3 access to list {buckets, objects, versions}, delete {objects, versions}. Cloudwatch permissions are optional and used to retrieve extra information about the target bucket.
{
.
.
.
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets",
"s3:DeleteObjectVersion",
"s3:ListBucketVersions",
"s3:ListBucket",
"s3:DeleteObject"
"cloudwatch:GetMetricData",
],
.
.
.
}
-
using prebuilt binaries:
See Releases
-
using
go
:go install github.com/soapiestwaffles/s3-nuke@latest
go run .
s3-nuke is usually meant to be run without any flags/arguments!
Usage: s3-nuke
Quickly destroy all objects and versions in an AWS S3 bucket.
Flags:
-h, --help Show context-sensitive help.
--version display version information
-e, --aws-endpoint=STRING override AWS endpoint address ($AWS_ENDPOINT)
--concurrency=5 amount of concurrency used during delete operations
--debug enable debugging output (warning: this is very verbose)
--warn display warning messages
This tool will return back the current and historical approximate number of objects in a bucket using CloudWatch.
-
using prebuilt binaries:
See Releases
-
using
go
:go install github.com/soapiestwaffles/s3-nuke/tools/s3-metrics@latest
go run tools/s3-metrics/main.go
s3-metrics tool: get bucket object metrics for a particular bucket
Flags:
-h, --help Show context-sensitive help.
-e, --aws-endpoint=STRING override AWS endpoint address ($AWS_ENDPOINT)
-r, --region="us-west-2" specify region to create bucket and objects in ($AWS_REGION)
$ go run tools/s3-metrics/main.go
🪣 my-s3-bucket
🌎 -> bucket located in us-west-2
2618829428639 ┤ â•â”€
2618804232609 ┤ â•â”€â”€â”€â•¯
2618779036578 ┤ â•â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â•¯
2618753840548 ┤ â•â”€â”€â”€â•¯
2618728644517 ┤ â•â”€â”€â•¯
2618703448487 ┤ â•â”€â”€â•¯
2618678252457 ┤ â•â”€â”€â”€â•¯
2618653056426 ┤ â•â”€â•¯
2618627860396 ┤ â•â”€â•¯
2618602664365 ┤ â•â”€â•¯
2618577468335 ┼──────────────╯
Byte Count for past 30 Days (Standard Storage)
Approx. bytes currently in bucket (standard storage): 2.6 TB
Metric last updated: 1 day ago at 2022-01-19 16:00:00 -0800 PST
5709667 ┤ â•
5709559 ┤ â•â”€â”€â•¯
5709450 ┤ â•â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â•¯
5709342 ┤ â•â”€â”€â•¯
5709234 ┤ â•â”€â•¯
5709126 ┤ â•â”€â”€â”€â”€â”€â•¯
5709017 ┤ â•â”€â•¯
5708909 ┤ â•â”€â•¯
5708801 ┤ â•â”€â•¯
5708692 ┤ â•â”€â•¯
5708584 ┼──────────────╯
Object Count for past 30 Days
Approx. objects currently in bucket: 5,709,667
Metric last updated: 1 day ago at 2022-01-19 16:00:00 -0800 PST
This tool was created mainly for testing s3-nuke. This tool will generate num-buckets
number of buckets, each containing num-objects
number of objects (containing random data), with num-versions
number of versions. If num-versions
< 2, s3-gen will create the buckets with versioning disabled.
- using
go
:
go install github.com/soapiestwaffles/s3-nuke/tools/s3-gen@latest
go run tools/s3-gen/main.go --num-buckets=INT --num-objects=INT --num-versions=INT
s3-nuke tool: generate a set of randomized buckets each containing a set of randomized objects and versions
Flags:
-h, --help Show context-sensitive help.
-e, --aws-endpoint=STRING override AWS endpoint address ($AWS_ENDPOINT)
-n, --num-buckets=INT number of buckets with randomized names to create
-o, --num-objects=INT number of random objects generated and put into buckets
-v, --num-versions=INT number of versions to create for each random object
-r, --region="us-west-2" specify region to create bucket and objects in
-p, --bucket-prefix="s3gen" prefix for every bucket name generated
--yes bypass user prompt and proceed with action automatically
$ go run tools/s3-gen/main.go --num-buckets=3 --num-objects=1000 --num-versions=10 --region="us-west-2"
=== RANDOM BUCKET GENERATOR ===
Create resources [1 bucket(s)]/[300 object(s)]/[10 version(s)]: y
create buckets 0s [====================================================================] 100%
create objects 16s [===>----------------------------------------------------------------] 8%
create versions 16s [========================================>---------------------------] 60%
- go >= 1.22
MIT License
Copyright (c) 2024 SoapiestWaffles
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.