Amazon S3 versioning is a feature that allows you to maintain multiple versions of an object in a single S3 bucket. This means that every time an object is modified, Amazon S3 keeps a copy of the previous version, enabling you to recover older versions of the object if needed. Versioning provides data protection, facilitates data recovery, and allows for the tracking of changes to your objects.
Enabling Versioning:
Versioning can be enabled or suspended on a bucket. Once enabled, versioning cannot be fully disabled, but it can be suspended. When versioning is suspended, new versions of objects will not be created, but existing versions are still retained.
You can enable versioning via the AWS Management Console, AWS CLI, or AWS SDKs.
Object Versions:
Each version of an object is assigned a unique version ID, which allows you to distinguish between different versions of the same object.
The version ID is automatically assigned by Amazon S3 when the object is uploaded or updated.
When you delete an object, S3 does not physically remove it but instead adds a delete marker (which can be reversed).
Versioned Object Behavior:
If you upload a new version of an object, it is assigned a new version ID, while the previous version remains accessible.
You can access a specific version by using its version ID in the URL or API request.
If you delete an object, S3 adds a delete marker. The object is still present in the bucket, but it appears deleted when you query the bucket. You can retrieve the object by its version ID.
Restoring Previous Versions:
You can easily restore a previous version of an object by copying it over the current version, essentially “reverting” to that version.
Lifecycle Policies:
You can set up lifecycle policies for versioned objects to automate the management of older versions, such as archiving them to Glacier or deleting them after a certain period.
Costs:
Versioning increases storage costs because all versions of an object are stored and incur charges. You will be billed for each version stored, so careful management of versions may be necessary.
Versioning states
Buckets can be in one of three states. The versioning state applies to all objects in the bucket. Storage costs are incurred for all objects in your bucket, including all versions. To reduce your Amazon S3 bill, you might want to delete previous versions of your objects when they are no longer needed.
To learn more, expand each of the following three categories.
Unversioned (default)
No new and existing objects in the bucket have a version.
Versioning-enabled
Versioning is enabled for all objects in the bucket. After you version-enable a bucket, it can never return to an unversioned state. However, you can suspend versioning on that bucket.
Versioning-suspended
Versioning is suspended for new objects. All new objects in the bucket will not have a version. However, all existing objects keep their object versions.