Protecting Objects with S3 Versioning
This lesson explains how versioning keeps every version of every object, protecting against accidental deletion and overwrites, and is a prerequisite for replication and Object Lock.
Learning outcomes
After completing this lesson, you will be able to:
- Describe how versions and delete markers work.
- Explain how lifecycle rules manage the cost of versioning.
- Explain how MFA Delete protects versions.
How versioning works
Versioning keeps every version of every object, so overwritten or deleted data can be recovered. Each write creates a new version with its own version ID, and earlier versions remain retrievable. A simple delete request does not remove data; it adds a delete marker, which hides the object, and deleting the marker restores it.
Only a delete request that names a specific version ID removes that version permanently. Once enabled, versioning can only be suspended, not disabled, and existing versions remain after suspension.
The following diagram shows the version stack of one object and the effect of each kind of delete.

Versioning behaviour
Managing cost
Every version of every object is stored and billed, so a versioned bucket whose objects are overwritten frequently can grow far beyond its visible size. Lifecycle rules control this growth: they move noncurrent versions to cheaper storage classes, expire them after a set number of days or keep only the newest few versions, and remove expired delete markers that no longer hide any versions. This keeps the protection that versioning provides for recent changes while limiting its cost.
Controlling version cost
MFA Delete
MFA Delete adds protection for the most destructive actions on a versioned bucket. Once it is enabled, which only the root user can do, permanently deleting an object version or changing the bucket's versioning state requires a valid MFA code in the request. This protects against accidental deletion and against an attacker who has obtained ordinary credentials, because they cannot permanently delete versions without the root user's MFA device.
Recovering a deleted report
A user deletes an important report from a versioned bucket, and another user overwrites a second report with an empty file.
| Problem | Recovery |
|---|---|
| Deleted report | Delete the delete marker; the previous version becomes current again |
| Overwritten report | Copy the previous version back as the current version |
| Old versions growing storage costs | A lifecycle rule expiring noncurrent versions after 90 days |
Without versioning, both reports would have been lost. MFA Delete would additionally stop a permanent deletion of the versions without an MFA code.
Can versioning be turned off once it is enabled on a bucket?
Show answer
No, only suspended. Existing versions remain, and new objects stop receiving new version IDs.
Exam Tips
Remember for the exam
- To recover objects that were accidentally deleted or overwritten, use versioning.
- To restore a deleted object in a versioned bucket, delete its delete marker.
- To control the cost of old versions, use lifecycle rules for noncurrent versions.
- To require MFA for permanent deletions, enable MFA Delete.