DEV Community

Zippy Wachira
Zippy Wachira

Posted on

Getting Started with AWS S3 Versioning

One of the more interesting features of Amazon S3 buckets is bucket versioning. Once enabled for a bucket, this feature allows a user to store multiple versions of the same object within the same bucket. Since the feature enables the bucket to preserve, retrieve, and restore every version of every object, it is much easier recover from both unintended user actions, such as accidental deletions, and application failures.

Uploading objects to S3 is quite a straightforward process. However, by default, if you upload an object with the same key name as an existing object, the original object is overwritten. Once you enable versioning, new objects are automatically assigned a version ID to distinguish them from the other objects.

In the bucket above, notice that both objects have the same key name but different version IDs. If another object is added, it is assigned its own unique Version ID.

Simple enough, right?

Now, the next question that would arise is how you interact with objects stored in a versioned bucket?

  1. Adding an object to a versioned bucket.
    Adding an object to a bucket follows the normal process of uploading an object to the bucket. Once you upload the object, it is given a unique version ID.

  2. Retrieving an object from a versioned bucket.
    A simple GET request will retrieve the most current version of the object.

To retrieve other versions, specify the version ID you want.

  1. Deleting an object from a versioned bucket. Unlike objects in buckets that are not enabled for versioning, a simple DELETE request cannot permanently delete an object. When S3 receives the DELETE request, it places a delete marker in the bucket. All versions of the deleted object remain in the bucket, and the delete marker is used as the most recent version of the object. However, the delete marker does not have any data; any GET requests to the marker return a 404 error. If you remove the marker, a GET request will retrieve the most recent version of the object.

In the diagram above, notice that the DELETE request on the bucket has resulted in the creation of a delete marker in the bucket.

To permanently delete versioned objects, you have to specify the object version with the DELETE request.


To delete a Delete Marker, you must specify its Version ID in the DELETE request.

Interesting right? I certainly hope you think so too.😊

Top comments (0)