DeleteObjects - Amazon Simple Storage Service

DeleteObjects

This operation enables you to delete multiple objects from a bucket using a single HTTP request. If you know the object keys that you want to delete, then this operation provides a suitable alternative to sending individual delete requests, reducing per-request overhead.

The request contains a list of up to 1000 keys that you want to delete. In the XML, you provide the object key names, and optionally, version IDs if you want to delete a specific version of the object from a versioning-enabled bucket. For each key, Amazon S3 performs a delete operation and returns the result of that delete, success, or failure, in the response. Note that if the object specified in the request is not found, Amazon S3 returns the result as deleted.

The operation supports two modes for the response: verbose and quiet. By default, the operation uses verbose mode in which the response includes the result of deletion of each key in your request. In quiet mode the response includes only keys where the delete operation encountered an error. For a successful deletion, the operation does not return any information about the delete in the response body.

When performing this operation on an MFA Delete enabled bucket, that attempts to delete any versioned objects, you must include an MFA token. If you do not provide one, the entire request will fail, even if there are non-versioned objects you are trying to delete. If you provide an invalid token, whether there are versioned keys in the request or not, the entire Multi-Object Delete request will fail. For information about MFA Delete, see MFA Delete.

Finally, the Content-MD5 header is required for all Multi-Object Delete requests. Amazon S3 uses the header value to ensure that your request body has not been altered in transit.

The following operations are related to DeleteObjects:

Request Syntax

POST /?delete HTTP/1.1 Host: Bucket.s3.amazonaws.com x-amz-mfa: MFA x-amz-request-payer: RequestPayer x-amz-bypass-governance-retention: BypassGovernanceRetention x-amz-expected-bucket-owner: ExpectedBucketOwner <?xml version="1.0" encoding="UTF-8"?> <Delete xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Object> <Key>string</Key> <VersionId>string</VersionId> </Object> ... <Quiet>boolean</Quiet> </Delete>

URI Request Parameters

The request uses the following URI parameters.

Bucket

The bucket name containing the objects to delete.

When using this API with an access point, you must direct requests to the access point hostname. The access point hostname takes the form AccessPointName-AccountId.s3-accesspoint.Region.amazonaws.com. When using this operation with an access point through the AWS SDKs, you provide the access point ARN in place of the bucket name. For more information about access point ARNs, see Using Access Points in the Amazon Simple Storage Service Developer Guide.

When using this API with Amazon S3 on Outposts, you must direct requests to the S3 on Outposts hostname. The S3 on Outposts hostname takes the form AccessPointName-AccountId.outpostID.s3-outposts.Region.amazonaws.com. When using this operation using S3 on Outposts through the AWS SDKs, you provide the Outposts bucket ARN in place of the bucket name. For more information about S3 on Outposts ARNs, see Using S3 on Outposts in the Amazon Simple Storage Service Developer Guide.

Required: Yes

x-amz-bypass-governance-retention

Specifies whether you want to delete this object even if it has a Governance-type Object Lock in place. You must have sufficient permissions to perform this operation.

x-amz-expected-bucket-owner

The account id of the expected bucket owner. If the bucket is owned by a different account, the request will fail with an HTTP 403 (Access Denied) error.

x-amz-mfa

The concatenation of the authentication device's serial number, a space, and the value that is displayed on your authentication device. Required to permanently delete a versioned object if versioning is configured with MFA delete enabled.

x-amz-request-payer

Confirms that the requester knows that they will be charged for the request. Bucket owners need not specify this parameter in their requests. For information about downloading objects from requester pays buckets, see Downloading Objects in Requestor Pays Buckets in the Amazon S3 Developer Guide.

Valid Values: requester

Request Body

The request accepts the following data in XML format.

Delete

Root level tag for the Delete parameters.

Required: Yes

Object

The objects to delete.

Type: Array of ObjectIdentifier data types

Required: Yes

Quiet

Element to enable quiet mode for the request. When you add this element, you must set its value to true.

Type: Boolean

Required: No

Response Syntax

HTTP/1.1 200 x-amz-request-charged: RequestCharged <?xml version="1.0" encoding="UTF-8"?> <DeleteResult> <Deleted> <DeleteMarker>boolean</DeleteMarker> <DeleteMarkerVersionId>string</DeleteMarkerVersionId> <Key>string</Key> <VersionId>string</VersionId> </Deleted> ... <Error> <Code>string</Code> <Key>string</Key> <Message>string</Message> <VersionId>string</VersionId> </Error> ... </DeleteResult>

Response Elements

If the action is successful, the service sends back an HTTP 200 response.

The response returns the following HTTP headers.

x-amz-request-charged

If present, indicates that the requester was successfully charged for the request.

Valid Values: requester

The following data is returned in XML format by the service.

DeleteResult

Root level tag for the DeleteResult parameters.

Required: Yes

Deleted

Container element for a successful delete. It identifies the object that was successfully deleted.

Type: Array of DeletedObject data types

Error

Container for a failed delete operation that describes the object that Amazon S3 attempted to delete and the error it encountered.

Type: Array of Error data types

Examples

Sample Request: Multi-object delete resulting in mixed success/error response

This example illustrates a Multi-Object Delete request to delete objects that result in mixed success and errors response. The following request deletes two objects from a bucket (bucketname). In this example, the requester does not have permission to delete the sample2.txt object.

POST /?delete HTTP/1.1 Host: bucketname.s3.<Region>.amazonaws.com Accept: */* x-amz-date: Wed, 30 Nov 2011 03:39:05 GMT Content-MD5: p5/WA/oEr30qrEEl21PAqw== Authorization: AWS AKIAIOSFODNN7EXAMPLE:W0qPYCLe6JwkZAD1ei6hp9XZIee= Content-Length: 125 Connection: Keep-Alive <Delete> <Object> <Key>sample1.txt</Key> </Object> <Object> <Key>sample2.txt</Key> </Object> </Delete>

Sample Response

The response includes a DeleteResult element that includes a Deleted element for the item that Amazon S3 successfully deleted and an Error element that Amazon S3 did not delete because you didn't have permission to delete the object.

HTTP/1.1 200 OK x-amz-id-2: 5h4FxSNCUS7wP5z92eGCWDshNpMnRuXvETa4HH3LvvH6VAIr0jU7tH9kM7X+njXx x-amz-request-id: A437B3B641629AEE Date: Fri, 02 Dec 2011 01:53:42 GMT Content-Type: application/xml Server: AmazonS3 Content-Length: 251 <?xml version="1.0" encoding="UTF-8"?> <DeleteResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Deleted> <Key>sample1.txt</Key> </Deleted> <Error> <Key>sample2.txt</Key> <Code>AccessDenied</Code> <Message>Access Denied</Message> </Error> </DeleteResult>

Sample Request: Deleting an object from a versioned bucket

If you delete an item from a versioning enabled bucket, all versions of that object remain in the bucket; however, Amazon S3 inserts a delete marker. For more information, see Object Versioning.

The following scenarios describe the behavior of a multi-object Delete request when versioning is enabled for your bucket.

Case 1 - Simple Delete: In the following sample request, the multi-object delete request specifies only one key.

POST /?delete HTTP/1.1 Host: bucketname.s3.<Region>.amazonaws.com Accept: */* x-amz-date: Wed, 30 Nov 2011 03:39:05 GMT Content-MD5: p5/WA/oEr30qrEEl21PAqw== Authorization: AWS AKIAIOSFODNN7EXAMPLE:W0qPYCLe6JwkZAD1ei6hp9XZIee= Content-Length: 79 Connection: Keep-Alive <Delete> <Object> <Key>SampleDocument.txt</Key> </Object> </Delete>

Sample Response

Because versioning is enabled on the bucket, Amazon S3 does not delete the object. Instead, it adds a delete marker for this object. The following response indicates that a delete marker was added (the DeleteMarker element in the response as a value of true) and the version number of the delete marker it added.

HTTP/1.1 200 OK x-amz-id-2: P3xqrhuhYxlrefdw3rEzmJh8z5KDtGzb+/FB7oiQaScI9Yaxd8olYXc7d1111ab+ x-amz-request-id: 264A17BF16E9E80A Date: Wed, 30 Nov 2011 03:39:32 GMT Content-Type: application/xml Server: AmazonS3 Content-Length: 276 <?xml version="1.0" encoding="UTF-8"?> <DeleteResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Deleted> <Key>SampleDocument.txt</Key> <DeleteMarker>true</DeleteMarker> <DeleteMarkerVersionId>NeQt5xeFTfgPJD8B4CGWnkSLtluMr11s</DeleteMarkerVersionId> </Deleted> </DeleteResult>

Case 2 - Versioned Delete

The following request attempts to delete a specific version of an object.

POST /?delete HTTP/1.1 Host: bucketname.s3.<Region>.amazonaws.com Accept: */* x-amz-date: Wed, 30 Nov 2011 03:39:05 GMT Content-MD5: p5/WA/oEr30qrEEl21PAqw== Authorization: AWS AKIAIOSFODNN7EXAMPLE:W0qPYCLe6JwkZAD1ei6hp9XZIxx= Content-Length: 140 Connection: Keep-Alive <Delete> <Object> <Key>SampleDocument.txt</Key> <VersionId>OYcLXagmS.WaD..oyH4KRguB95_YhLs7</VersionId> </Object> </Delete>

Sample Response

In this case, Amazon S3 deletes the specific object version from the bucket and returns the following response. In the response, Amazon S3 returns the key and version ID of the object deleted.

HTTP/1.1 200 OK x-amz-id-2: P3xqrhuhYxlrefdw3rEzmJh8z5KDtGzb+/FB7oiQaScI9Yaxd8olYXc7d1111xx+ x-amz-request-id: 264A17BF16E9E80A Date: Wed, 30 Nov 2011 03:39:32 GMT Content-Type: application/xml Server: AmazonS3 Content-Length: 219 <?xml version="1.0" encoding="UTF-8"?> <DeleteResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Deleted> <Key>SampleDocument.txt</Key> <VersionId>OYcLXagmS.WaD..oyH4KRguB95_YhLs7</VersionId> </Deleted> </DeleteResult>

Case 3 - Versioned delete of a delete marker

In the preceding example, the request refers to a delete marker (instead of an object), then Amazon S3 deletes the delete marker. The effect of this operation is to make your object reappear in your bucket. Amazon S3 returns a response that indicates the delete marker it deleted (DeleteMarker element with value true) and the version ID of the delete marker.

HTTP/1.1 200 OK x-amz-id-2: IIPUZrtolxDEmWsKOae9JlSZe6yWfTye3HQ3T2iAe0ZE4XHa6NKvAJcPp51zZaBr x-amz-request-id: D6B284CEC9B05E4E Date: Wed, 30 Nov 2011 03:43:25 GMT Content-Type: application/xml Server: AmazonS3 Content-Length: 331 <?xml version="1.0" encoding="UTF-8"?> <DeleteResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Deleted> <Key>SampleDocument.txt</Key> <VersionId>NeQt5xeFTfgPJD8B4CGWnkSLtluMr11s</VersionId> <DeleteMarker>true</DeleteMarker> <DeleteMarkerVersionId>NeQt5xeFTfgPJD8B4CGWnkSLtluMr11s</DeleteMarkerVersionId> </Deleted> </DeleteResult>

Sample Response

In general, when a multi-object Delete request results in Amazon S3 either adding a delete marker or removing a delete marker, the response returns the following elements.

<DeleteMarker>true</DeleteMarker> <DeleteMarkerVersionId>NeQt5xeFTfgPJD8B4CGWnkSLtluMr11s</DeleteMarkerVersionId>

Sample Request: Malformed XML in the request

This example shows how Amazon S3 responds to a request that includes a malformed XML document. The following request sends a malformed XML document (missing the Delete end element).

POST /?delete HTTP/1.1 Host: bucketname.s3.<Region>.amazonaws.com Accept: */* x-amz-date: Wed, 30 Nov 2011 03:39:05 GMT Content-MD5: p5/WA/oEr30qrEEl21PAqw== Authorization: AWS AKIAIOSFODNN7EXAMPLE:W0qPYCLe6JwkZAD1ei6hp9XZIee= Content-Length: 104 Connection: Keep-Alive <Delete> <Object> <Key>404.txt</Key> </Object> <Object> <Key>a.txt</Key> </Object>

Sample Response

The response returns the error messages that describe the error.

HTTP/1.1 200 OK x-amz-id-2: P3xqrhuhYxlrefdw3rEzmJh8z5KDtGzb+/FB7oiQaScI9Yaxd8olYXc7d1111ab+ x-amz-request-id: 264A17BF16E9E80A Date: Wed, 30 Nov 2011 03:39:32 GMT Content-Type: application/xml Server: AmazonS3 Content-Length: 207 <?xml version="1.0" encoding="UTF-8"?> <Error> <Code>MalformedXML</Code> <Message>The XML you provided was not well-formed or did not validate against our published schema</Message> <RequestId>264A17BF16E9E80A</RequestId> <HostId>P3xqrhuhYxlrefdw3rEzmJh8z5KDtGzb+/FB7oiQaScI9Yaxd8olYXc7d1111ab+</HostId> </Error>

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: