Table of Contents
As one has to maintain multiple copies in order to have backups of data, having multiple copies without any proper metadata may lead to some disastrous situations. Previously, as we have learnt about “How To Create an S3 Bucket on AWS“, today we are going to learn about a solution (version control) for maintaining different versions of a particular type of data, further, we will be understanding about “version control on an S3 bucket”.
Step 1: Create a new S3 bucket
We are going to create an S3 bucket, as shown below we have created a bucket with a name “versioning-geekylane“.

Now, after creating this bucket, we have to make the “versioning-geekylane” bucket as “public“.
If you do not know how to make an S3 bucket public, then please follow -> Make an S3 Bucket Public and look for “Step 6“

Step 2: Enable versioning or version control on S3 bucket
From the “Amazon S3” dashboard, click on the “S3 bucket” you want to enable versioning on, after that look for “Properties” tab and from there you will be seeing something like shown below.

After that, click on the “Versioning” block and you will be asked as shown in the screenshot below.
Select “Enable versioning” as we did, and click on “Save” icon.

You will be seeing that now the “Versioning” is enabled.

Step 3: Upload a file to S3 bucket as “Version = 1”
In this step, we are going to create a file, here we are using “geekylane.txt” as our file holding the contents as shown below.
Note: This will be the “version 1” of this file.

The file has been successfully uploaded to the S3 bucket “versioning-geekylane“.
Note: The size of the file with “version 1” is 37.0 B

Step 4: Access the file stored in S3 bucket
Note: As we have already made “versioning-geekylane” bucket public, we can directly access the contents resides under it without making any further changes to permissions.
Make sure, before accessing the file you enabled the public access to the file, otherwise, it will give you an “AccessDenied” error.
Simply copy the “Object URL” as shown below.

After copying the “URL“, paste that in the “URL bar” in your browser and hit enter.
Note: The URL and file will be completely different in your case.

From above, we can see that the “geeklane.txt” file stored in “versioning-geekylane” is easily accessible.
Step 5: Update the file to “Version = 2” and upload it to S3 bucket
Now, we have changed the contents of the “geekylane.txt” with the following.

Upload the updated “geekylane.txt” file to the “versioning-geekylane” bucket, as shown in the picture below.
Note: The size of the file with “version 2” is 71.0 B

Again, copy the “Object URL” of this updated “version 2” of “geekylane.txt” file, as shown in the image below.

Paste that “URL” in the browser’s “URL bar“.
Question: Wait! what? – Why is it giving us the “AccessDenied” error?
Answer: Because we have uploaded a new version of the “geekylane.txt” file, so in order to access it, we have to again make changes to its permissions and make it public.

Making the file public.

Accessing the updated “version 2” of the “geekylane.txt” file via a web browser.
From below, you can see that now we are able to access the updated “geekylane.txt” file.

Step 6: View all the versions of a file stored in an S3 bucket
Click on the toggle button “Show” in the front of the “Versions” as shown below.
After that you will be able to see all the versions of a particular file.

Click on “Hide” to only view the latest version of the file.

Step 7: Deleting the files stored in an S3 bucket with versioning enabled
From the picture, you can see that we are deleting the “geekylane.txt” file.
Question: Will it be going to delete all the versions of the “geekylane.txt” files?
Answer: No, it will be only going to delete the “latest version” of the file, in this case only the “version 2” of “geekylane.txt” file is going to be deleted.

After deleting the “latest version” of the file, you will be seeing something like shown below, if you do not have any other files already stored in your S3 bucket.

Click on the “Show” button to view the versions currently available.
Question: Why our “geekylane.txt” is not deleted?
Answer: By default, Amazon S3 will not delete the file, instead it will create a “Delete Marker” to the file.
Question: So, how do we actually delete a file stored in an S3 bucket enabled with versioning?
Answer: Simple solution is to first enable or go to the “show” all versions view so that you can see all the versions of a particular file and from there delete the version you want to be deleted.
From below, now we are in the “all version” view of a file, if we delete the “Delete Marker” as well as the “Latest Version” of the file, eventually we will be able to delete the “version 2” of our “geekylane.txt” file.

Click on the “Delete” option under “Actions” tab in order to delete the “Delete Marker” of a file.

Confirm the deletion of “Delete Marker“.

After deleting the “Delete Marker“, we are again left with the “version 1” and “version 2” of the file.

Click on the “Hide” icon to go back to the normal view.

Comment here