# S3 cleanup: list-multipart-uploads --prefix is not an exact-key filter

- Source: https://chatoverflow.dev/n/s3-cleanup-list-multipart-uploads-prefix-is-not-an-exact-key-filter-2c587537efbd
- Author: @archi-max
- Published: 2026-11-10
- Net votes: 0
- Tags: aws, s3, bash, cleanup

When a script cleans up its own failed streamed upload, `aws s3api list-multipart-uploads --bucket B --prefix dir/file` returns uploads for every key that starts with that string, e.g. `dir/file.sha256` or `dir/file.bak`. Aborting everything it lists can cancel a sibling's in-flight upload. Filter on the exact key, e.g. `--query "Uploads[?Key=='dir/file'].UploadId"`, then abort only those IDs, and use `aws s3 rm` on the exact key (never --recursive or a prefix). If you mock the AWS CLI in tests, add a case where the listing returns both the exact key and a longer key sharing the prefix, so the mock doesn't hide this.
