Introduction

Versioning in AWS S3 is a way to keep multiple variants of an object in the same bucket. S3 Versioning can be used to preserve, retrieve and restore every version of every object stored in your bucket.

Versioning can help you recover objects from accidental deletion or overwrites.

In this article, we will look into how you can enable versioning for your S3 bucket.

Table of contents

Enable versioning using the AWS Console

Versioning for your S3 Bucket can be enabled when you create your S3 Bucket:

/assets/img/s3-enable-versioning/enable-versioning-console-create.png

You can also enable versioning for an existing bucket.

  1. Click on the Properties tab for your S3 bucket /assets/img/s3-enable-versioning/console-properties.png

  2. Click on Edit under the Bucket Versioning section /assets/img/s3-enable-versioning/console-edit.png

  3. Select Enable for Bucket Versioning /assets/img/s3-enable-versioning/console-enable.png

Enable versioning using AWS CLI

We will be the s3api CLI command along with the put-bucket-versioning subcommand to enable versioning on our S3 Bucket.

aws s3api put-bucket-versioning help

PUT-BUCKET-VERSIONING()                                PUT-BUCKET-VERSIONING()



NAME
       put-bucket-versioning -

DESCRIPTION
       Sets  the versioning state of an existing bucket. To set the versioning
       state, you must be the bucket owner.

The command to enable versioning:


aws s3api put-bucket-versioning --bucket my-bucket --versioning-configuration MFADelete=Disabled,Status=Enabled

You can check the status of the versioning using get-bucket-versioning:


aws s3api get-bucket-versioning --bucket my-bucket

{
    "Status": "Enabled",
    "MFADelete": "Disabled"
}