Introduction (Amazon Simple Storage Service) is an object storage service offered by Amazon Web Services. For S3 buckets, if versioning is enabled, users can preserve, retrieve, and restore every version of the object stored in the bucket. Amazon S3 In this article, we will understand how to enable versioning for a bucket and retrieve all versions of an object from AWS web interface as well as . Python boto library Versioning of Bucket Bucket versioning can be changed with a toggle button from the AWS web console in the bucket properties. We can do the same with Python boto3 library. boto3 bucket_name = s3 = boto3.resource( ) versioning = s3.BucketVersioning(bucket_name) print(versioning.status) versioning.enable() versioning.suspend() import 'avilpage' 's3' # check status # enable versioning # disable versioning Retrieving Objects Once versioning is enabled, we can store multiple versions of an object by uploading an object multiple times with the same key. We can write a simple script to generate a text file with a random text and upload it to S3. random string boto3 file_name = key = file_name s3 = boto3.client( ) open(file_name, ) fh: data = .join(random.choice(string.ascii_letters) _ range( )) fh.write(data) s3.upload_file(key, bucket_name, file_name) import import import 'test.txt' 's3' with 'w' as '' for in 10 If this script is executed multiple times, the same file gets overridden with a different version id with the same key in the bucket. We can see all the versions of the file from the bucket by selecting the file and then clicking drop-down at Latest version. We can write a script to retrieve and show contents of all the versions of the test.txt file with the following script. boto3 bucket_name = s3_client = boto3.client( ) versions = s3_client.list_object_versions(Bucket=bucket_name) version versions: version_id = versions[ ][ ][ ] file_key = versions[ ][ ][ ] response = s3.get_object( Bucket=bucket_name, Key=file_key, VersionId=version_id, ) data = response[ ].read() print(data) import 'avilpage' 's3' for in 'Versions' 0 'VersionId' 'Versions' 0 'Key' 'Body' Conclusion Object versioning is useful to protect data from unintended overwrites. In this article, we learnt how to change bucket versioning, upload multiple versions of same file and retrieving all versions of the file using AWS web console as well as boto3.