Amazon S3 Versioning Using CLI

Amazon Simple Storage Service (S3) is a highly scalable, durable, and secure object storage service provided by AWS. The S3 offers versioning ability which would let you keep several versions of an object in the same bucket. In other words, it means that when you add an object with the similar key (name) into a versioned bucket, S3 keeps all versions of the object thus making possible for users to get back previous versions as and when required. This article will go into great detail about AWS S3 versioning including terminologies involved, how it is implemented and some common use cases as well.

Understanding Of Primary Terminologies

  • Versioning: Whenever an object is uploaded or modified, the versioning feature guarantees that a new version of it will be created thus enabling you to have multiple versions of an object in any single S3 bucket.
  • Object: In Amazon S3, an object means a simple entity stored in a bucket that might be either file, text or any other sort of data.
  • Bucket: All objects in S3 are stored within a bucket which serves as the basic resource for this service and therefore containers for those items within S3 are called buckets.
  • Marker: For each versioned object in a versioned S3 bucket, there is always a marker which is nothing but unique identifiers representing all such versions thereby making their retrieval and tracing very easy.
  • Delete Marker: A placeholder for a deleted object version.
  • Suspended Versioning: Disables versioning on an S3 bucket, making it behave like a standard bucket.

Amazon S3 Versioning: A Step-By-Step Guide

Step 1: Access the AWS Management Console

  • Log in to your AWS Management Console using your credentials.

Step 2: Navigate To Amazon S3

  • From the services menu, select “Amazon S3” Service by clicking on “Create Bucket” as shown in the below screenshot.

Step 3: Enabling Versioning

  • To enable Amazon S3 versioning on an S3 bucket by default it enabled when you creating a bucket if you disabled and you want to enable versioning navigate to the bucket properties in the S3 Bucket, select “Edit,” and then click “Enable versioning.”

Step 4: Uploading Objects

  • Upload objects to a versioned bucket using the AWS Management Console, AWS CLI, or SDKs. Each upload creates a new version of the object.

Step 5: Listing Object Versions

  • Use API or AWS Management Console to list all versions of an object in a versioned bucket. Each version will have a unique marker.

Step 6: Deleting Object Versions

  • Delete specific versions of an object by specifying the version ID. When you delete a version, a delete marker is created for that version.

Step 7: Restoring Previous Versions

  • To Restore previous version , you will need to select the bucket name where the object is stored.
  • Choose names of objects from this list.
  • Choose versions.
  • Amazon S3 presents all the versions of an item.
  • Select the check box that corresponds to the version ID for which you want to retrieve versions.
  • Choose actions, then download and save an object.

Amazon S3 Versioning Using AWS CLI: A Step-By-Step Guide

Follow the AWS CLI installation instructions available at Install the latest version of the AWS CLI.

Step 1 : Configure the AWS CLI

Use “aws configure” to set up your AWS CLI with your AWS access key ID, secret access key, default region, and output format. you can find access key ID and secret access key in IAM Security Credentials.

Step 2: Create S3 Bucket

  • Use the “aws s3 mb” command

Step 3 : Enabling Versioning

  • use the “aws s3api put-bucket-versioning” command

Step 4: Uploading Objects

  • To upload a object to an S3 bucket, use the “aws s3 cp” command

Step 5: Listing Object Versions

  • To list all object versions in an S3 bucket, you can use the “aws s3api list-object-versions” command

Step 6 : Deleting Object Versions

  • To delete a specific version of an object in an S3 bucket, use “aws s3api delete-object –bucket bucket-name –key object-key –version-id version-id”

  • Replace bucket-name with the name of S3 bucket, object-key with the key of the object you want to delete and version-id with the version ID of the object.

Step 7: Restoring Previous Versions

  • To restore a specific version of an object in S3 bucket, use the “aws s3api restore-object –bucket bucket-name –key object-key –version-id version-id –restore-request Days=number-of-days”.

  • By using AWS S3 versioning, you can increase data durability and recoverability for your stored objects, ensuring the integrity of your data over time.

Amazon S3 Versioning – FAQ’s

Can I Disable Versioning Once It’s Enabled?

Yes, you can disable versioning on an S3 bucket, which will remove all existing versions of objects.

How Can I Restore A Deleted Object From A Versioned Bucket?

You can restore a deleted object by deleting the delete marker for that object.

Is There A Limit To The Number Of Versions I Can Store?

No, there is no limit to the number of versions you can store in a versioned bucket.

How Does Versioning Affect Storage Costs?

Versioning may increase storage costs since each version of an object is stored separately.

Can I use lifecycle policies with versioned objects?

Yes, you can use lifecycle policies to manage versions of objects in a versioned bucket.



Contact Us