Versioning in S3
Welcome to CloudAffaire and this is Debjeet
In the last blog post, we have discussed how to create a bucket and object in AWS S3.
In this blog post, we are going to discuss versioning in S3. We are also going to enable versioning in S3 bucket.
Versioning in S3
AWS S3 provides versioning to keep multiple version of an object in the same bucket. Using versioning, you can keep multiple version of the same object in your S3 bucket. In one bucket, for example, you can have two objects with the same key, but different version IDs, such as photo.jpg (version 1) and photo.jpg (version 2). You can use versioning to preserve, retrieve, and restore every version of every object stored in your Amazon S3 bucket. With versioning, you can easily recover from both unintended user actions and application failures.
Versioning-enabled buckets enable you to recover objects from accidental deletion or overwrite.
• If you delete an object, instead of removing it permanently, Amazon S3 inserts a delete marker, which becomes the current object version. You can always restore the previous version.
• If you overwrite an object, it results in a new object version in the bucket. You can always restore the previous version.
Buckets can be in one of three states: un-versioned (the default), versioning-enabled, or versioning-suspended. Once you enable versioning to a bucket, it can never return to a un-versioned state. You can, however, suspend versioning on that bucket. AWS S3 does not support selective versioning to objects and once enabled, it applies to all the objects inside the bucket. When you enable versioning to a bucket, AWS assigns a unique id to each new objects inside the bucket. Objects stored in your bucket before you set the versioning state have a version ID of null.
Next, we are going to enable versioning to an existing S3 bucket and upload multiple version of the same object. We are also going to delete a versioned object and recover it.
Enable Versioning to S3 bucket:
Step 1: Login to AWS console and click ‘S3’ located under Storage.
Step 2: Click on the bucket.
Note: If you don’t have any bucket created yet, follow the previous demo and create one.
Step 3: Upload an image file.
Warning: Charges apply depending upon the region and file size.
Step 4: Navigate to ‘Properties’ and click ‘Versioning’.
Step 5: Select ‘Enable versioning’ and click ‘Save’.
Note: Once you enable versioning to a bucket, you cannot remove versioning on the same bucket.
Step 6: Click ‘Overview’. Notice version tab is enabled in your bucket. Click ‘Show’.
Note: Enabling versioning does not affect the current objects in the bucket but to the future objects.
Step 7: Upload a new image with the same name and extension to your bucket.
Note: A new version id has been assigned to the new image.
Next, we are going to delete the latest version of the object
Delete versioning enabled object in S3 bucket:
Step 1: Click ‘Hide’. Select the image and from Actions select ‘Delete’.
Note: In order to view the delete marker and restore the deleted object, you need to hide the version details by clicking ‘Hide’. Else latest version of the object will be deleted without delete marker and you will not be able to recover it. I am not sure why we can’t have delete marker if version id details are shown. Any comment is much appreciated.
Step 2: Click ‘Delete’.
Note: It appears like all the version of the object is deleted. However, S3 has not deleted the versioning enabled object. You can see the object by clicking ‘Show’.
Step 3: Click ‘Show’.
Note: AWS S3 has assigned a delete marker to object.
Recover deleted object with versioning enabled in S3:
Step 1: In order to recover the deleted object, we just need to delete the delete marker version of the object. Select the object version that has delete marker and from Actions click ‘Delete’.
Step 2: Click ‘Delete’.
Delete marker has been successfully deleted. Now if you click ‘Hide’, you will be able to view the object again.
Hope you have enjoyed this article, in the next blog, we will create Cross-Region Replication between two S3 buckets in different regions.