Is there really no fast way to delete an S3 bucket with 1M+ objects?

I have an s# bucket that has accumulated a lot of objects over time (millions) that now needs to be cleared and deleted. removing the objects both by UI and CLI is very slow. I also tried expiring the objects with the lifecycle approach without good success.

Is there any fast brute force way to clear and then delete an S3 bucket I am missing?

Why can’t you use Lifecycle Rules to delete the objects? Set the rule to delete current and non-current versioned objects (if you use versioning) at 1 day.

What’s the issue?

Agreed with the commenter above that your described use case of ‘cleaning out accumulated objects’ is the perfect scenario for a life cycle rule. What was the rule that you used that didn’t have success? It will take some time, it’s not instant.

Remove using prefix if you have one, dont loop thru keys.
If you want to delete all in the bucket, just empty the bucket

aws s3 rm s3://mybucket --recursive

If you go this route and not the above-mentioned and me-seconded AWS Batch or Lifecycle rule route, you’re gonna want to background that command with a “&” or use screen to let it run if you run it on a workspace or remote machine.

Im pretty sure AWS recommends this method in their documentation too

Lifecycle rule is the bets way to go, will cover it in 1-3 days. There’s no fast way.

Anything else will give you API charges

Can you expand on why lifecycle rules didn’t work for you? Set it to the minimum and give a few days to work through the bucket.

If you need to be surgical, S3 Batch is a great option. Schedule a bucket inventory, filter in Excel, and upload to Batch.

Lifecycle rules still rack up API charges.

Deletes are free (assuming standard storage) for lifecycle and API. List isn’t which you will need to use for the API deletes.

As does r/AWS whenever this question comes up :slight_smile:

Thanks /u/TangerineDream82 /u/Dizzybro /u/or9ob - posting the official documentation and locking this thread as it has been answered. :slight_smile:

Hi /u/kodridrocl - please follow the guidance here to resolve this issue.