AWS S3 Bucket Versioning: Protecting S3 data using bucket versioning & listing of buckets with version using python sdk(boto3)

By | 20th January 2019

In this blog post, we are trying to use versioning for S3 buckets.

One of the important concepts of buckets is it to keep the versioning of the buckets. This helps if you have deleted the object/bucket by mistake.

More informationis available @ https://docs.aws.amazon.com/AmazonS3/latest/user-guide/enable-versioning.html

Version can be also enabled from the aws console.

Click on Create Bucket –> 1. Give the bucket details and click next –> 2. Configure Bucket and check box enable versioning

Enable versioning for s3 bucket

However as in my earlier posts, I am trying to use boto3 to enabale the versioning for S3 buckets. Few scripts which might be helpful

  1. List all the buckets for which the versioning is not enabled
    https://github.com/rajeevrn/myscripts/blob/master/aws/s3listbucketnoversion.py
  2. Enable versioning for the ALL bucket if it is not enabled
    https://github.com/rajeevrn/myscripts/blob/master/aws/s3enablebucketversion.py

Listing all the buckets available with the account.
:~/git/myscripts/aws$ python s3listbucketnoversion.py
Listing of the S3 buckets which do not have versioning
testingdeletes3bucket1
testingdeletes3bucket2

Enable version for the buckets:(this will enable versioning for ALL the buckets)
:~/git/myscripts/aws$ python s3enablebucketversion.py
Listing of the S3 buckets which do not have versioning
Enabling versioning for bucket:testingdeletes3bucket1
Enabling versioning for bucket:testingdeletes3bucket2

Re-ran the script again and now we do not have any buckets without versioning.
:~/git/myscripts/aws$ python s3listbucketnoversion.py
Listing of the S3 buckets which do not have versioning
:~/git/myscripts/aws$