S3 Versioning allows multiple versions of objects to be stored in a single S3 bucket. When versioning is enabled for a bucket, S3 automatically assigns a unique version ID to each object upload or change. This prevents accidental overwriting and enables restoration of previous versions. Versioning is configured at the bucket level and version IDs are opaque strings assigned by S3 to distinguish object versions.
2. What is S3 Versioning?
S3 Versioning is used to keep multiple versions of an object in one bucket and enable
you to restore objects that are accidentally deleted or overwritten. For example, if we
delete an object, instead of removing it permanently, Amazon S3 inserts a delete
marker, which becomes the current object version. We can then restore the previous
version.
3. How S3 Versioning works
Each S3 bucket that you create has a versioning subresource associated with it. By default,
your bucket is unversioned, and the versioning subresource stores the empty versioning
configuration.
To enable versioning, you can send a request to Amazon S3 with a versioning configuration
that includes a status.
The bucket owner and all authorized IAM users can enable versioning. The bucket owner is
the AWS account that created the bucket (the root account)
4. Version IDs
If you enable versioning for a bucket, Amazon S3 automatically generates a unique
version ID for the object that is being stored. For example, in one bucket you can have
two objects with the same key but different version IDs, such as photo.gif (version
111111) and photo.gif (version 121212).
Each object has a version ID, whether or not S3 Versioning is enabled. If S3 Versioning is
not enabled, Amazon S3 sets the value of version ID to null. If you enable S3 Versioning,
Amazon S3 assigns a version ID value for the object. This value distinguishes it from other
versions of the same key.
Only Amazon S3 generates version IDs, and they cannot be edited. Version IDs are
Unicode, UTF-8 encoded, URL-ready, opaque strings that are no more than 1,024 bytes
long. The following is an example:
3sL4kqtJlcpXroDTDmJ+rmSpXd3dIbrHY+MTRCxf3vjVBH40Nr8X8gdRQBpUML
Uo
5. Versioning workflows
When you PUT an object in a versioning-enabled bucket, the noncurrent
version is not overwritten. The following figure shows that when a new
version of photo.gif is PUT into a bucket that already contains an object
with the same name, the original object (ID = 111111) remains in the
bucket, Amazon S3 generates a new version ID (121212), and adds the
newer version to the bucket.
This functionality prevents you from accidentally overwriting or deleting
objects and gives you the opportunity to retrieve a previous version of an
object.
When you DELETE an object, all versions remain in the bucket and
Amazon S3 inserts a delete marker, as shown in the following figure.
6. The delete marker becomes the current version of the object. By default, GET
requests retrieve the most recently stored version. Performing a simple GET
Object request when the current version is a delete marker returns a 404 Not
Found error, as shown in the following figure.
However, you can GET a noncurrent version of an object by specifying its
version ID. In the following figure, you GET a specific object version, 111111.
Amazon S3 returns that object version even though it's not the current version.
7. You can permanently delete an object by specifying the version you want to
delete. Only the owner of an Amazon S3 bucket can permanently delete a
version. The following figure shows how DELETE versionId permanently
deletes an object from a bucket and that Amazon S3 doesn't insert a delete
marker.
You can add more security by configuring a bucket to enable MFA (multi-
factor authentication) delete. When you do, the bucket owner must include
two forms of authentication in any request to delete a version or change the
versioning state of the bucket. For more information, see Configuring MFA
delete.
New versions are created only when you PUT a new object. Be aware that
certain actions like COPY work by implementing PUT. Taking actions that
modify the current object will not create a new version because they do not
PUT a new object. This includes actions such as changing the tags on an
object.
8. Steps To Enable Versioning
Follow these steps to use the AWS Management Console to enable versioning on an S3
bucket.
To enable or disable versioning on an S3 bucket
Sign in to the AWS Management Console and open the Amazon S3 console at
https://console.aws.amazon.com/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.