# How to delete an S3 bucket with versioning enabled

How-to guides · Updated 17 November 2026

**Short answer:** A versioned bucket can only be deleted once every object version and every delete marker is gone. In the S3 console, use Empty on the bucket (it removes all versions), then Delete. On the CLI, aws s3 rb --force is not enough because it only removes current versions; delete the versions with list-object-versions and delete-objects, or use a lifecycle rule for very large buckets. This is permanent.

## Why the bucket "isn't empty"

With versioning on, deleting an object just adds a *delete marker* on top; the older versions stay and are still billed. `aws s3 rm --recursive` and `aws s3 rb --force` work on current versions only, so afterwards the bucket still holds every old version, and `DeleteBucket` fails with [BucketNotEmpty](https://cloudconsole.dev/errors/s3-bucketnotempty). Suspending versioning doesn't help either: it stops new versions, but existing ones remain.

## Console: Empty, then Delete

1. Open the Amazon S3 console and select the bucket in the bucket list.
2. Choose **Empty**, type the confirmation text, and confirm. This deletes all objects, including all versions and delete markers.
3. When it reports success, select the bucket again and choose **Delete**, then type the bucket name to confirm.

Leave the page open while emptying a large bucket; for millions of objects, the lifecycle approach below is more practical.

## CLI: delete all versions, then the bucket

**Destructive.** Double-check the bucket name and account (`aws sts get-caller-identity`) before running.

```
BUCKET=my-bucket

# Delete object versions, 1000 at a time (delete-objects' per-request limit)
while :; do
  aws s3api list-object-versions --bucket "$BUCKET" --max-items 1000 \
    --query '{Objects: Versions[].{Key: Key, VersionId: VersionId}}' \
    --output json > batch.json
  grep -q '"Key"' batch.json || break
  aws s3api delete-objects --bucket "$BUCKET" --delete file://batch.json \
    --query 'length(Deleted)'
done

# Same again for delete markers
while :; do
  aws s3api list-object-versions --bucket "$BUCKET" --max-items 1000 \
    --query '{Objects: DeleteMarkers[].{Key: Key, VersionId: VersionId}}' \
    --output json > batch.json
  grep -q '"Key"' batch.json || break
  aws s3api delete-objects --bucket "$BUCKET" --delete file://batch.json \
    --query 'length(Deleted)'
done

aws s3api delete-bucket --bucket "$BUCKET"
```

If `delete-objects` returns an `Errors` list, read it: `AccessDenied` usually means a bucket policy, MFA delete or Object Lock is blocking you.

## Very large buckets: let a lifecycle rule do it

Listing and deleting millions of versions from a laptop is slow. A lifecycle rule deletes them in the background at no request cost to you:

```
{"Rules": [{
  "ID": "empty-for-deletion", "Status": "Enabled", "Filter": {},
  "Expiration": {"Days": 1},
  "NoncurrentVersionExpiration": {"NoncurrentDays": 1},
  "AbortIncompleteMultipartUpload": {"DaysAfterInitiation": 1}
}]}
```

Apply it with `aws s3api put-bucket-lifecycle-configuration --bucket my-bucket --lifecycle-configuration file://rule.json`. Expiration happens asynchronously, usually over a day or two. Once only expired-object delete markers remain, add `"ExpiredObjectDeleteMarker": true` in the `Expiration` block in place of `Days` (the two can't be combined), wait again, then delete the bucket.

## Check before you delete

- **Is anything still writing to it?** CloudFront origins, application config, replication rules and log delivery will fail or recreate objects.
- **Object Lock or MFA delete** (`aws s3api get-bucket-versioning --bucket my-bucket` shows `MFADelete`) prevents deletion until retention ends or MFA is supplied.
- **The name is released.** Bucket names are global; once deleted, someone else can claim it, which matters if anything still references it.

## Questions

### How do I enable or check versioning with the AWS CLI?

aws s3api put-bucket-versioning --bucket my-bucket --versioning-configuration Status=Enabled turns it on; aws s3api get-bucket-versioning --bucket my-bucket shows the current status. You can suspend versioning later but never return a bucket to unversioned.

### Why does aws s3 rb --force fail on a versioned bucket?

It deletes only current object versions. Older versions and delete markers remain, so the bucket is not empty when rb tries to delete it.

### Does deleting the bucket delete its versions?

You cannot delete the bucket until all versions are gone, so yes: emptying it permanently deletes every version, with no recovery.

## When this happens away from your desk

Deleting buckets is something you want to do carefully at a desk, not in a hurry. CloudConsole, a phone app for AWS, is built with production guardrails so destructive actions are deliberate.

[About the CloudConsole app](https://cloudconsole.dev/aws-console-app) · [Download on the App Store](https://apps.apple.com/app/cloudconsole-for-aws/id6835419710)

## Sources

- [Deleting a general purpose bucket](https://docs.aws.amazon.com/AmazonS3/latest/userguide/delete-bucket.html)
- [Retaining multiple versions of objects with S3 Versioning](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Versioning.html)

## Related

- [aws s3 rb](https://cloudconsole.dev/cli/s3-rb)
- [aws s3api list-object-versions](https://cloudconsole.dev/cli/s3api-list-object-versions)
- [aws s3api delete-objects](https://cloudconsole.dev/cli/s3api-delete-objects)
- [BucketNotEmpty: The bucket you tried to delete is not empty](https://cloudconsole.dev/errors/s3-bucketnotempty)
- [aws s3api put-bucket-lifecycle-configuration](https://cloudconsole.dev/cli/s3api-put-bucket-lifecycle-configuration)
- [How to find S3 bucket size](https://cloudconsole.dev/how-to/find-largest-s3-buckets)
- [How to restore a deleted S3 object](https://cloudconsole.dev/how-to/restore-deleted-s3-object)

---

Source: https://cloudconsole.dev/how-to/delete-s3-bucket-with-versioning

CloudConsole is an independent iPhone and Android app for Amazon Web Services by Cloudconcur Ltd. It is not affiliated with Amazon Web Services.
