Deleting object versions from a versioning-enabled bucket - Amazon Simple Storage Service

Welcome to the new Amazon S3 User Guide! The Amazon S3 User Guide combines information and instructions from the three retired guides: Amazon S3 Developer Guide, Amazon S3 Console User Guide, and Amazon S3 Getting Started Guide.

Deleting object versions from a versioning-enabled bucket

You can delete object versions from Amazon S3 buckets whenever you want. You can also define lifecycle configuration rules for objects that have a well-defined lifecycle to request Amazon S3 to expire current object versions or permanently remove noncurrent object versions. When your bucket is version-enabled or versioning is suspended, the lifecycle configuration actions work as follows:

  • The Expiration action applies to the current object version. Instead of deleting the current object version, Amazon S3 retains the current version as a noncurrent version by adding a delete marker, which then becomes the current version.

  • The NoncurrentVersionExpiration action applies to noncurrent object versions, and Amazon S3 permanently removes these object versions. You cannot recover permanently removed objects.

For more information, see Managing your storage lifecycle.

Delete request use cases

A DELETE request has the following use cases:

  • When versioning is enabled, a simple DELETE cannot permanently delete an object.

    Instead, Amazon S3 inserts a delete marker in the bucket, and that marker becomes the current version of the object with a new ID. When you try to GET an object whose current version is a delete marker, Amazon S3 behaves as though the object has been deleted (even though it has not been erased) and returns a 404 error.

    The following figure shows that a simple DELETE does not actually remove the specified object. Instead, Amazon S3 inserts a delete marker.

  • To delete versioned objects permanently, you must use DELETE Object versionId.

    The following figure shows that deleting a specified object version permanently removes that object.

To delete object versions

You can delete object versions in Amazon S3 using the console, AWS SDKs, or the REST API.

  1. Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/.

  2. In the Buckets list, choose the name of the bucket that contains the object.

  3. In the Objects list, choose the name of the object.

  4. Choose Versions.

    Amazon S3 shows all the versions for the object.

  5. Select the check box next to the Version ID for the versions that you want to retrieve.

  6. Choose Delete.

  7. In Permanently delete objects?, enter permanently delete.

    Warning

    When you permanently delete an object version, the action cannot be undone.

  8. Choose Delete objects.

    Amazon S3 deletes the object version.

For examples of deleting objects using the AWS SDKs for Java, .NET, and PHP, see Deleting Amazon S3 objects. The examples for deleting objects in nonversioned and versioning-enabled buckets are the same. However, for versioning-enabled buckets, Amazon S3 assigns a version number. Otherwise, the version number is null.

For information about using other AWS SDKs, see Sample Code and Libraries.

To a delete a specific version of an object

  • In a DELETE, specify a version ID.

Example — Deleting a specific version

The following example shows how to delete version UIORUnfnd89493jJFJ of photo.gif.

DELETE /photo.gif?versionId=UIORUnfnd89493jJFJ HTTP/1.1 Host: bucket.s3.amazonaws.com Date: Wed, 12 Oct 2009 17:50:00 GMT Authorization: AWS AKIAIOSFODNN7EXAMPLE:xQE0diMbLRepdf3YB+FIEXAMPLE= Content-Type: text/plain Content-Length: 0

Related topics

For more information about deleting object versions, see the topics below: