Versioning
Versioning is a means of keeping the multiple forms of an object in the same S3 bucket. Versioning can be used to retrieve, preserve and restore every version of an object in S3 bucket.
For example, bucket consists of two objects with the same key but with different version ID’s such as photo.jpg (version ID is 11) and photo.jpg (version ID is 12).
Versioning-enabled buckets allow you to recover the objects from the deletion or overwrite. It serves two purposes:
- If you delete an object, instead of deleting the object permanently, it creates a delete marker which becomes a current version of an object.
- If you overwrite an object, it creates a new version of the object and also restores the previous version of the object.
Note: Once you enable the versioning of a bucket, then it cannot be disabled. You can suspend the versioning.
Versioning state can be applied to all the objects in a bucket. Once the versioning state is enabled, all the objects in a bucket will remain versioned, and they are provided with the unique version ID. Following are the important points:
- If the versioning state is not enabled, then the version ID of the objects is set to null. When the versioning is not enabled, existing objects are not changed or are not affected.
- The bucket owner can suspend the versioning to stop the object versions. When you suspend the versioning, existing objects are not affected.
Let’s understand the concept of versioning through an example.
- Sign in to the AWS Management Console.
- Move to the S3 services.
- No, click on the “Create bucket” to create a new bucket.
- Enter the bucket name which must be unique.
- Click on the “create” button.
In the above screen, we observe that the bucket “jtpbucket” is created with the default settings, i.e., bucket and objects are not public.
- Now, I want to see some objects in a bucket; we need to make a bucket public. Move to the “Edit public access settings“, uncheck all the settings, and then save the settings.
- After saving the settings, the screen appears is shown below:
Type the “confirm” in a textbox to confirm the settings. Click on the “confirm” button.
- When the settings are confirmed, the screen appears as shown below:
The above screen shows that the objects in a bucket have become public.
- Now, we add the versioning to our bucket. Move to the properties of a bucket, i.e., jtpbucket and click on the versioning.
- On clicking on the versioning, the screen appears as shown below:
We can either enable or suspend the versioning. Suppose we enable the versioning and save this setting, this adds the versioning to our bucket.
- We now upload the files to our bucket.
- Now, we click on the “Add files” to add the files in our bucket. When a file is uploaded, the screen appears as shown below:
In the above screen, we observe that version.txt file is uploaded.
- To run the version.txt file, we have to make it public from the Actions dropdown menu.
- When a file becomes public, we can run the file by clicking on its object URL. On clicking on the object URL, the screen appears as shown below:
- Now, we create the second version of the file. Suppose I change the content of the file and re-upload it, then it becomes the second version of the file.
In the above screen, we change the content from “version 1” to “version 2” and then save the file.
- Now, we upload the above file to our bucket.
- After uploading the file, two versions of a file are created.
From the above screen, we observe that either we can hide or show the versions.
- When we click on the “show”, we can see all the versions of a file.
From the above screen, we can see both the versions of a file and currently uploaded file become the latest version. Both the files are of same size, i.e., 18.0 B and storage class, i.e., Standard.
- To run the version.txt file, we have to make it public from the Actions dropdown menu.
- Now, move to the properties of a file and click on the object URL.
Click on the Object URL.
- On clicking on the Object URL, we can see the output, i.e., the content of the currently uploaded file.
- Now, we delete an object. Move to the Actions dropdown menu and click on the Delete.
- On deleting the object, the screen appears as shown below:
We observe that the bucket becomes empty.
- However, when we click on the Show Version, we can see all the versions of a file, i.e., Delete marker and other two versions of a file.
We observe from the above screen that the object is not permanently deleted; it has been restored. Therefore, the versioning concept is used to restore the objects.
- If you want to restore the object, delete the “delete marker” by clicking on the Actions dropdown menu and click on the Delete.
- Click on the “Hide” Versions, we will observe that the file has been restored.
Important points to be remembered:M
- It stores all versions of an object (including all writes and even if you delete an object).
- It is a great backup tool.
- Once the versioning enabled, it cannot be disabled, only suspended.
- It is integrated with lifecycle rules.
- Versioning’s MFA Delete capability uses multi-factor authentication that can be used to provide the additional layer of security.