Enabling versioning on buckets
You can use S3 Versioning to keep multiple versions of an object in one bucket. This section provides examples of how to enable versioning on a bucket using the console, REST API, Amazon SDKs, and Amazon Command Line Interface (Amazon CLI).
Note
When you enable versioning on a bucket for the first time, it might take a short
amount of time for the change to be fully propagated. While this change is propagating,
you may encounter intermittent HTTP 404 NoSuchKey
errors for requests to objects created or
updated after enabling versioning. We recommend that you wait for 15 minutes after
enabling versioning before issuing write operations
(PUT
or
DELETE
)
on objects in the bucket.
For more information about S3 Versioning, see Retaining multiple versions of objects with S3 Versioning. For information about working with objects that are in versioning-enabled buckets, see Working with objects in a versioning-enabled bucket.
To learn more about how to use S3 Versioning to
protect data, see Tutorial: Protecting data on Amazon S3 against accidental deletion or application bugs using
S3 Versioning, S3 Object Lock, and S3 Replication
Each S3 bucket that you create has a versioning subresource associated with it. (For more information, see Bucket configuration options.) By default, your bucket is unversioned, and the versioning subresource stores the empty versioning configuration, as follows.
<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> </VersioningConfiguration>
To enable versioning, you can send a request to Amazon S3 with a versioning configuration that includes a status.
<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Status>Enabled</Status> </VersioningConfiguration>
To suspend versioning, you set the status value to Suspended
.
The bucket owner and all authorized users can enable versioning. The bucket owner is the Amazon Web Services account that created the bucket (the root account). For more information about permissions, see Identity and Access Management for Amazon S3.
The following sections provide more detail about enabling S3 Versioning using the console, Amazon CLI, and the Amazon SDKs.
Follow these steps to use the Amazon Web Services Management Console to enable versioning on an S3 bucket.
To enable or disable versioning on an S3 bucket
Sign in to the Amazon Web Services Management Console and open the Amazon S3 console at https://console.amazonaws.cn/s3/
. -
In the Buckets list, choose the name of the bucket that you want to enable versioning for.
-
Choose Properties.
-
Under Bucket Versioning, choose Edit.
-
Choose Suspend or Enable, and then choose Save changes.
Note
You can use Amazon multi-factor authentication (MFA) with versioning. When you use MFA with versioning, you must provide your Amazon Web Services account’s access keys and a valid code from the account’s MFA device to permanently delete an object version or suspend or reactivate versioning.
To use MFA with versioning, you enable MFA Delete
. However, you can't enable
MFA Delete
using the Amazon Web Services Management Console. You must use the Amazon Command Line Interface (Amazon CLI) or the API.
For more information, see Configuring MFA delete.
The following example enables versioning on an S3 bucket.
aws s3api put-bucket-versioning --bucket
amzn-s3-demo-bucket1
--versioning-configuration Status=Enabled
The following example enables S3 Versioning and multi-factor authentication (MFA) delete on a bucket.
aws s3api put-bucket-versioning --bucket
amzn-s3-demo-bucket1
--versioning-configuration Status=Enabled,MFADelete=Enabled --mfa "SERIAL 123456
"
Note
Using MFA delete requires an approved physical or virtual authentication device. For more information about using MFA delete in Amazon S3, see Configuring MFA delete.
For more information about enabling versioning using the Amazon CLI, see put-bucket-versioning
The following examples enable versioning on a bucket and then retrieve versioning
status using the Amazon SDK for Java and the Amazon SDK for .NET. For information about using other
Amazon SDKs, see the Amazon Developer
Center