Step-by-Step Guide: Enabling Versioning on Amazon S3

Step-by-Step Guide: Enabling Versioning on Amazon S3

Introduction

Amazon S3 (Simple Storage Service) is a scalable and durable cloud-based storage service by Amazon Web Services (AWS) for storing and retrieving data, files, and objects. In this tutorial, we will explore the capability of enabling versioning in Amazon S3. Whether you're a seasoned cloud architect or a newcomer to the cloud, understanding how versioning works and how to implement it can be a game-changer in maintaining data consistency, recovering from accidental deletions, and complying with regulatory requirements.

What is versioning in S3?

S3 versioning is a feature on Amazon S3 that allows you to preserve, retrieve, and manage multiple versions of objects stored in a bucket.

Key concepts

  • It is used to preserve, retrieve, and restore every version of every object stored in an S3 bucket.

  • Done at the S3 Bucket level.

  • Can be enabled from the AWS Console / SDKs / API.

  • Once enabled, cannot be completely disabled, the alternative is placing the bucket in a "versioning-suspended" state.

  • A drawback of having multiple versions of an object is you are billed multiple times (since the objects are getting stored in S3 each time).

  • In order to avoid having multiple versions of the same object, S3 has a feature called Lifecycle Management. This allows us to decide on what to do when multiple versions of an object are piling up.

  • One advantage of versioning is, we can provide permissions on versioned objects, i.e., we can define which version of an object is public and which one is private.

Preparation

  • Create an AWS Account: If you don't already have an AWS account, you'll need to create one. Go to the AWS website and follow the sign-up process.

  • Access Key and Secret Access Key: To interact with AWS services programmatically or through the AWS CLI, you'll need to generate access keys. These keys consist of an Access Key ID and a Secret Access Key. They are essential for authenticating your AWS requests.

  • Configure AWS CLI: If you plan to use the AWS Command Line Interface (CLI), you'll need to install it on your local machine. Once installed, configure the CLI with your access key and region. This step is necessary for performing actions on your AWS resources, including S3 buckets.

  • Select the Target S3 Bucket: Decide which S3 bucket you want to enable versioning for. Ensure you have the necessary permissions to modify the bucket settings.

Practical example

In the following steps, we will guide you through the process of enabling versioning in Amazon S3:

  • Create new bucket

  • Enable versioning

  • In order to test it, upload a new object. (For the purpose of this tutorial we have used a fancy orc avatar):

  • Make the bucket public with a Bucket policy, use the Policy generator and grant public access to getObject in S3:

  • Finally, we upload the same object but with different color balance to differentiate clearly the versions:

Conclusion

In conclusion, enabling versioning in Amazon S3 is a fundamental step towards enhancing the resilience, security, and control of your data in the cloud. By following the steps outlined in this guide, you've empowered yourself with a powerful tool for data preservation, recovery, and compliance. Versioning ensures that no data is lost to accidental deletions, provides a historical record of changes, and safeguards your critical information.