How to enable Versioning on AWS S3 Bucket (using AWS Console & CLI)

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:
You can also enable versioning for an existing bucket.
-
Click on the Properties tab for your S3 bucket
-
Click on Edit under the Bucket Versioning section
-
Select
Enable
for Bucket Versioning
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"
}