Bars for three delete strategies on 2,500 objects: trusting HTTP 200 sends 2,500 keys and leaves 35 objects, retrying everything sends 7,500, retrying only failed keys sends 2,550

A bulk delete to an S3-compatible bucket can come back with HTTP 200 and still leave objects behind. The answer is in the body: every key that failed has its own error entry. If your code only checks the status, you will report a clean bucket that is not clean.

We built a small S3 stand-in that fails the same keys every run, pointed boto3, the AWS CLI and rclone at it, and counted what each one did. Same 2,500 objects every time, so you can repeat it.

The test setup

  • 2,500 objects named file-0000.txt to file-2499.txt, so three DeleteObjects requests (1,000 + 1,000 + 500).
  • 25 transient keys (index ends in 13 when divided by 100): answer InternalError the first two times they are in a request, then delete fine.
  • 10 permanent keys (index leaves 7 when divided by 250): answer AccessDenied every time and stay.
  • Every response is HTTP 200, as S3 does for a request it understood. Like S3, the stand-in refuses a request with no checksum header and one with more than 1,000 keys.

Three ways to loop over the keys

StrategyHTTP statusesKeys sentObjects leftTold you?
Check the status only200, 200, 2002,50035No
Retry everything, 3 passesall 2007,50010No: 10 left, nothing says why
Retry only failed keysall 2002,55010Yes: the 10 keys with their error code

The failed-key loop sent 2,500 keys in round 1, then 25 in round 2 and 25 in round 3, when the 25 transient keys finally went through. It is 4,950 fewer keys than three full passes.

The loop that works

Treat the error code as the decision: retry the ones that can succeed later, report the ones that cannot. Do not retry AccessDenied; it will fail the same way every time.

python
import time
import boto3

RETRYABLE = {"InternalError", "SlowDown", "ServiceUnavailable", "RequestTimeout"}

def delete_all(s3, bucket, keys, max_rounds=5):
    pending, permanent = list(keys), {}
    for rnd in range(1, max_rounds + 1):
        failed = []
        for i in range(0, len(pending), 1000):          # 1,000 keys per request
            batch = pending[i:i + 1000]
            r = s3.delete_objects(Bucket=bucket, Delete={
                "Objects": [{"Key": k} for k in batch], "Quiet": True})
            for e in r.get("Errors", []):               # HTTP 200 does not mean done
                if e["Code"] in RETRYABLE:
                    failed.append(e["Key"])
                else:
                    permanent[e["Key"]] = e["Code"]
        if not failed:
            break
        pending = failed                                # only the failed keys go again
        time.sleep(0.5 * 2 ** rnd)
    return permanent, failed                            # permanent: give up; failed: ran out of rounds
  • Quiet mode returns only the failures. On the first 1,000 keys the verbose answer listed 986 Deleted and 14 errors; quiet listed 0 and the same 14. For big batches quiet is a smaller answer with the same information.
  • Whole-request failures are a different case. When the stand-in answered one request with 503 SlowDown, boto3 retried it by itself (the server saw 503, then 200). With the SDK's retries switched off it raised ClientError: SlowDown and deleted nothing. The SDK does not retry per-key errors inside a 200.
  • 1,001 keys in one request were refused with MalformedXML. Split at 1,000.

What the command-line tools do

CommandRequests it madeExit codeObjects left
aws s3api delete-objects (aws-cli/1.46.3), first 1,000 keys1 DeleteObjects0 (14 errors printed as JSON)14 of 1,000
aws s3 rm --recursive (aws-cli/1.46.3)2,500 DeleteObject, 0 DeleteObjects110
rclone delete (v1.76.0)about 2,544 DeleteObject, 0 DeleteObjects110

Two things to take from that. The raw API call (<code>s3api delete-objects</code>) exits 0 even though 14 keys failed, so a shell script has to read the JSON, not the exit code. The friendlier commands (<code>aws s3 rm</code>, <code>rclone delete</code>) delete one key per request, so they never see this response at all, and they exit non-zero when a key fails. rclone's request count moved between runs (it retries failed deletes itself), so read that one as a rough figure.

What to do with this

  • Read Errors (boto3) or the Error elements (raw XML) after every DeleteObjects call, not the status.
  • Retry only the keys that failed, with a pause that doubles, and a round limit.
  • Split permanent from retryable by code, and put the permanent keys in your log or your report.
  • Compare the count you meant to delete with a listing at the end if the delete matters (a cleanup before closing an account, say).

The same advice holds on any S3-compatible bucket, including a tport.space bucket: the response format comes from the S3 API. If you copy first and delete later, verifying a bucket copy covers the check before you delete.

S3-compatible buckets with no egress fees, for the files you clean up and the ones you keep.

Explore tport.space

Test record and sources

  • Run on 2026-11-15 on one Mac, loopback only: Python 3.12, boto3 1.44.3, aws-cli/1.46.3, v1.76.0. The stand-in is not tport.space or AWS; it shows how clients react to the response shape, not how any real service behaves under load. Error codes and the failure pattern are ours, chosen to be fixed.
  • AWS docs: DeleteObjects (up to 1,000 keys; per-key success or failure in the response; verbose and quiet modes; Content-MD5 or a checksum header required), boto3 delete_objects (Deleted and Errors in the response).