Introduction

AWS S3 Versioning allows you to keep multiple variants of an object in the same bucket. Versioning helps you recover from more easily from accidental deletes or overwrites.

By default, Versioning is disabled on buckets. In this article, we will look at how to enable and suspend versioning.

Enabling versioning using AWS CLI

Versioning applies to all the objects in a bucket. It cannot be applied to a subset of the objects in a bucket. Two things to keep in mind when you enable versioning:

  • All new objects are versionined and given a unique version ID
  • Objects that already existed in the bucket before versioning was enabled will be versioned and given a unique version ID when they are modified by future requests.

Versioning can be enabled using the put-bucket-versioning command in the aws s3api CLI. To enable versioning, we will set the Status as Enabled.

aws s3api put-bucket-versioning --bucket my_bucket --versioning-configuration Status=Enabled

You can confirm that versioning was enabled by using the get-bucket-versioning command.


aws s3api get-bucket-versioning --bucket my_bucket

{
    "Status": "Enabled"
}

Suspending versioning using AWS CLI

After enabling versioning on a bucket, it cannot be disabled. Versioning can only be suspended after it has been enabled. Things to note:

  • Suspending versioning stops any new versions of the objects from being created.
  • Suspending versioning has no impact on existing objects in the bucket.

To suspend versioning on a bucket, we can set the Status as Suspended.

aws s3api put-bucket-versioning --bucket my_bucket --versioning-configuration Status=Suspended

You can confirm that versioning was enabled by using the get-bucket-versioning command.


aws s3api get-bucket-versioning --bucket my_bucket

{
    "Status": "Suspended"
}