AWS S3 Versioning
- Versioning in Amazon S3 is a means of keeping multiple variants of an object in the same bucket.
- You can use the S3 Versioning feature to preserve, retrieve, and restore every version of every object stored in your buckets.
- Versioning-enabled buckets can help you recover objects from accidental deletion or overwrite.
- After versioning is enabled for a bucket, if Amazon S3 receives multiple write requests for the same object simultaneously, it stores all of those objects.
- For example, if you delete an object in the S3 versioned enabled bucket, Amazon S3 inserts a delete marker instead of removing the object permanently.
- The delete marker becomes the current object version.
Buckets can be in one of three states:
- Unversioned (the default)
- Versioning-enabled
- Versioning-suspended
How S3 Versioning works
- S3 Versioning keeps multiple versions of an object in one bucket and enables you to restore objects that are accidentally deleted or overwritten.
- For example, if you delete an object, instead of removing it permanently, Amazon S3 inserts a delete marker, which becomes the current object version. You can then restore the previous version.
Version ID

- 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) andphoto.gif
(version 121212). - If you don’t enable S3 Versioning, Amazon S3 sets the value of the version ID to null. If you enable S3 Versioning, Amazon S3 assigns a version ID value for the object.
Versioning workflows

- When you
PUT
an object in a versioning-enabled bucket, the current version is overwritten. - The following figure shows that when a new version
photo.gif
isPUT
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.
Deleting 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.

- 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 a404 Not Found
error, as shown in the above diagram.

- However, you can
GET
a noncurrent version of an object by specifying its version ID. In the following figure, youGET
a specific object version, 111111.
Permanently Delete

- 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.