How To Protect Objects From Accidental Deletion And Overwrite Using S3 Object Versioning

Deepak Surendran
Tensult Blogs
Published in
4 min readFeb 8, 2019

This Blog has been moved from Medium to blogs.tensult.com. All the latest content will be available there. Subscribe to our newsletter to stay updated.

AWS S3 is an Object storage service. It is used to store Flat files like Images, Videos, and other static files. For more information on S3, visit the Amazon documentation here.

Here we are going to discuss S3 Object Versioning.

S3 Object Versioning is one of the most salient features in Amazon S3. Object versioning is used to avoid unintended overwrite and deletion. Versioning is not enabled by default and this feature is used to keep multiple versions of objects at the same time in the bucket.

If we enable versioning on the bucket, we cannot delete an object directly. All versions remain in the bucket and a delete marker is introduced which becomes the current version. So if you need to delete an object, you need to remove that delete marker also. Existing objects in your bucket do not change and only future requests behavior changes. If we put an object retrieval request, the current version of the object will always return.

Now we are going to discuss how to enable versioning.

  1. Go to the AWS management console, then select S3 from the service menu and go to the bucket that you want to enable versioning

2. Click on Properties and then click on bthe ox named Versioning as shown in the below picture.

3. Now select the option Enable versioning. You can’t disable versioning once you have enabled it, but you can suspend it. It is one of the limitations of S3 object versioning

4. For suspending versioning, select the suspend versioning option and save it,

Now we are going to check how versioning works on a version-enabled bucket,

  1. In this example, I created one bucket called versioningexample123 and enabled versioning,

2. Upload an Image (Amazon.png) to the bucket.

3. The image is now available in the bucket.

4. We can see the Image by clicking the Image URL.

5. Upload another Image wiimagee same name (Amazon.png).

6. We uploaded two Images with the same name (Amazon.png) but only one Image is visible in the bucket

7. The first image is hidden and not missing. We can see it by clicking on the button which says ‘Show’. Once clicked, it will show us both the versions of the file.

8. Click on ‘Hide’ and then click on the image URL of the latest file; it will show the latest version of the image.If you need to see the older version, please click on the show option again and click the URL of the older version.

9. Let us check what happens if we try to delete an object.

10. If you delete an object from a version-enabled bucket, Amazon will put one delete marker there and it becomes the current version and you can easily recover the non-current versions.

In the above scenario, we saw that we can recover the deleted data if we enabled versioning. That is one of the Advantages of Object Versioning. There is no additional cost for this feature. The same objects as a whole, we end up paying only for the extra storage of the multiple versions of an object. For example, if you are storing a 100 MB file with 3 copies with a minor difference, then you need to pay for the entire 300 MB storage. So keep this thing in your mind before enabling versioning.

This Blog has been moved from Medium to blogs.tensult.com. All the latest content will be available there. Subscribe to our newsletter to stay updated.

--

--