S3 file versioning hands On
Tags: aws, cloud, beginners, tutorial
Published: 2021-08-02 11:22:17

We studied about S3 file versioning in the last part . In this part we will see how to start file versioning in S3 and what are its advantages.

* Go to your S3 dashboard 


* Select the bucket that we used in last exercise while deploying a static site in S3
![S3 versioning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7nxf27h5chjeqolx3rdp.png)

* Go to the properties tag. The first setting is bucket versioning.
![S3 versioning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vy3ko7netk8cfl94rxfb.png)

* Click on edit in bucket versioning

![S3 versioning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m2w5pqtlfh3vfnzkxaf6.png)
* Select enable and save changes
![S3 versioning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hycv6b3bc49b8v664omn.png)

* Bucket versioning is enabled now in the bucket

Now let us see what it affects and how it can be useful

* Change the contents of the index.html file and upload it again I've changes the contents to the following.

```html
<html>
    <head>
        <title>Test s3</title>
    </head>
    <body>
        <h1>Ajit Singh</h1>
        <p>Hello world new!</p>
    </body>
</html>

```

* Upload the new file again
![S3 versioning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x9scwlbr2c1vwm73rx4x.png)
* Enable show versions from bucket dashboard you will see that you have two versions of the file
![S3 versioning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d5v6fpkhxmgmls522zdu.png)

* Now on checking the website link you will see the contents changes
![S3 versioning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v5v87tc3cso01w52kuq8.png)

## Now let us see how to recover our old file

* To recover the old file we can select a specific version on the dashboard and delete it then we will recover our old file
![S3 versioning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/28mgp4lxf5fy1ussu4hc.png)
![S3 versioning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kek897wtnfluvnvos15a.png)
* Now let us again go to our website link. we will see that our file is reverted back.

![S3 versioning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/afx3hxdrfdbgg1mfiwp1.png)
* Let us now try to delete the last index.html file but turn off show versions.
![S3 versioning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o2knew8avbfc853mzdwn.png)
* You will see that this is not an option of permanently delete but a delete
![S3 versioning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1aqrl2j6tw1m6mfqm8ye.png)
* After you delete the object you will see you bucket is empty 
![S3 versioning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r8zr3duw0gop8vu062vv.png)
* Enable show versions you will see that it is not actually deleted but S3 adds a delete marker on it
![S3 versioning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9jvs4tug8gzqapdm4w7y.png)

* We can now recover the object by deleting the delete marker on the object same way we deleted the other version
![S3 versioning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ro3ia7itbt1uxgapqem8.png)
![S3 versioning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g1xt3feczffvwmdfhrdd.png)
![S3 versioning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/grkyeflchm2gacnauqqq.png)

* Voila we have recover the version

So here we see why bucket versioning is so important in S3 and why this should definitely be enabled for important buckets. We have already created a S3 bucket but how to see logs if retrieval of file is failing. Next time we will study how to enable logging in S3 buckets.