S3 delete an object

Removes an object. Requires WRITE permission set on the containing bucket. If bucket versioning is enabled, the delete operation creates a delete marker. To permanently delete a specific version, you must specify the versionId subresource.

Syntax

Delete the latest version of an object:

DELETE /BUCKET/OBJECT HTTP/1.1

Delete a specific version of an object:

Syntax

DELETE /BUCKET/OBJECT?versionId=VERSION_ID HTTP/1.1

Conditional delete

You can perform a conditional delete so that the object is deleted only if certain metadata conditions are met. This helps prevent accidental deletion if the object has changed since it was last read.

IBM Storage Ceph supports conditional delete operations uniformly for both general purpose buckets and directory buckets. This behavior applies to all supported conditional delete options in Ceph.

The following table lists the supported conditional delete options
Option Description Supported bucket type
if-match <ETag> Deletes the object only if the specified ETag matches the current ETag of the object. Returns 412 Precondition Failed if it does not match. General purpose and directory buckets.
if-match-last-modified-time <timestamp> Deletes the object only if its LastModifiedTime matches the specified timestamp. Returns 412 Precondition Failed if it does not match. Directory buckets only.
if-match-size <bytes> Deletes the object only if the object size matches the specified size in bytes. Returns 412 Precondition Failed if it does not match. Directory buckets only.
Note: You can use these conditional parameters individually or in combination. If the condition fails, the server returns HTTP status code 412 Precondition Failed.

Examples

Example 1: Delete an object unconditionally.
aws s3api delete-object \
  --bucket my-example-bucket \
  --key logs/2025/system.log
 
Example 2: Delete a specific version of an object.
aws s3api delete-object \
  --bucket my-versioned-bucket \
  --key data/file.txt \
  --version-id 3HL4kqCxf3vjVBH40NrjfkdXh6xYzl7l
 
Example 3: Conditional delete using ETag.
aws s3api delete-object \
  --bucket my-dir-bucket \
  --key reports/january.csv \
  --if-match "b1946ac92492d2347c6235b4d2611184"
 
Example 4: Conditional delete using size and last modified time (directory bucket only).
aws s3api delete-object \
  --bucket amzn-s3-demo-bucket-usw2-az1-x-s3 \
  --key analytics/summary.json \
  --if-match-last-modified-time 2025-09-20T10:25:00Z \
  --if-match-size 2048