# BucketNotEmpty: The bucket you tried to delete is not empty

AWS error fixes · Updated 17 November 2026

**Short answer:** S3 only deletes empty buckets, and in a versioned bucket "empty" includes every old object version and delete marker, which aws s3 rm and aws s3 rb --force don't remove. Empty the bucket from the console's Empty button, or delete all versions and delete markers with list-object-versions and delete-objects, then delete the bucket.

## Why it happens

```
An error occurred (BucketNotEmpty) when calling the DeleteBucket operation:
The bucket you tried to delete is not empty. You must delete all versions in the bucket.
```

The common trap: `aws s3 ls s3://my-bucket` shows nothing, yet deletion still fails. Listing only shows current objects. If versioning is (or ever was) enabled, deleting an object just adds a delete marker and keeps the old versions, and those still count.

## Unversioned bucket: the quick way

If versioning was never enabled, this removes all objects and then the bucket. **It is irreversible.**

```
aws s3 rb s3://my-bucket --force
```

Check first:

```
aws s3api get-bucket-versioning --bucket my-bucket
```

An empty response means versioning was never turned on. `Enabled` or `Suspended` means old versions may exist; use the next section.

## Versioned bucket: delete every version

**Destructive: this permanently deletes all data in the bucket.** Run it with the bucket name double-checked. The loop deletes a batch at a time, staying under the 1,000-key limit of a single `DeleteObjects` call, until nothing is left:

```
B=my-bucket
while :; do
  aws s3api list-object-versions --bucket "$B" --max-items 500 --output json \
    --query '{Objects: [Versions, DeleteMarkers][][].{Key: Key, VersionId: VersionId}}' > /tmp/batch.json
  [ "$(jq '.Objects | length' /tmp/batch.json)" -eq 0 ] && break
  aws s3api delete-objects --bucket "$B" --delete file:///tmp/batch.json --query 'length(Errors || `[]`)'
done
aws s3api delete-bucket --bucket "$B"
```

For buckets with millions of objects this is slow. A cheaper route is a lifecycle rule that expires current versions, permanently deletes noncurrent versions after one day and removes expired delete markers; S3 then empties the bucket in the background (it can take a day or more), after which you delete it. The console's **Empty** action also handles versions, and works well for small and medium buckets.

## When something still blocks deletion

| Blocker | What to do |
|---|---|
| Object Lock retention or legal hold | Objects can't be deleted until retention expires (compliance mode can't be shortened). Plan for it; you can't force it. |
| Bucket policy denying `s3:DeleteObject` or `s3:DeleteBucket` | Delete errors show `AccessDenied` in the `Errors` list; adjust the policy first |
| Something keeps writing | Access logs, CloudTrail, Config or an application still delivers objects; stop the writer first |
| MFA delete enabled | Permanently deleting versions requires the root user's MFA |

## CloudFormation DELETE_FAILED

Stacks fail to delete with `The bucket you tried to delete is not empty` because CloudFormation doesn't empty buckets. Empty it with the steps above, then retry the stack deletion; or retry while retaining the bucket resource and delete it later. If you want stacks to clean up after themselves in non-production, CDK's `autoDeleteObjects` option adds a custom resource that empties the bucket on delete.

## Questions

### How do I delete a non-empty S3 bucket with the AWS CLI?

For an unversioned bucket, aws s3 rb s3://bucket --force. For a versioned one, delete all object versions and delete markers with list-object-versions and delete-objects, then run aws s3api delete-bucket.

### Why does my S3 bucket say not empty when it has no objects?

It has old object versions or delete markers from versioning. They don't appear in a normal listing but must be deleted before the bucket can be.

### Does aws s3 rb --force delete versions?

No. It removes current objects only, so on a versioned bucket it leaves old versions and delete markers and the bucket delete still fails.

## When this happens away from your desk

Bucket deletion is rarely urgent, but it is exactly the kind of destructive action that deserves a second look. CloudConsole, a phone app for AWS, is built with production guardrails so viewing resources on a phone doesn't come with a one-tap path to deleting them.

[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

- [Emptying a general purpose bucket](https://docs.aws.amazon.com/AmazonS3/latest/userguide/empty-bucket.html)
- [Deleting a general purpose bucket](https://docs.aws.amazon.com/AmazonS3/latest/userguide/delete-bucket.html)

## Related

- [How to delete an S3 bucket with versioning enabled](https://cloudconsole.dev/how-to/delete-s3-bucket-with-versioning)
- [aws s3 rb](https://cloudconsole.dev/cli/s3-rb)
- [aws s3api delete-objects](https://cloudconsole.dev/cli/s3api-delete-objects)
- [aws s3api list-object-versions](https://cloudconsole.dev/cli/s3api-list-object-versions)
- [aws s3api put-bucket-lifecycle-configuration](https://cloudconsole.dev/cli/s3api-put-bucket-lifecycle-configuration)
- [aws cloudformation delete-stack](https://cloudconsole.dev/cli/cloudformation-delete-stack)

---

Source: https://cloudconsole.dev/errors/s3-bucketnotempty

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