Lesson 4 of 6 Amazon S3

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.

How versioning handles writes and deletes. Each write adds a version with its own ID. A simple delete adds a delete marker on top, which hides the object without removing data, and deleting the marker restores it. Only a delete that names a version ID removes that version permanently.
The version IDs are illustrative. Every version is stored and charged, which is why lifecycle rules expire noncurrent versions.
True or false

Versioning behaviour

Exam skills 1.3.5 · 2.2.5

Check how S3 versioning handles deletes.

Log in to try this activity Interactive activities are free with an account.

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.

Select all that apply

Controlling version cost

Exam skills 4.1.5 · 4.1.9

Identify the lifecycle actions that control the cost of versioning.

Log in to try this activity Interactive activities are free with an account.

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.

Worked example

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.

ProblemRecovery
Deleted reportDelete the delete marker; the previous version becomes current again
Overwritten reportCopy the previous version back as the current version
Old versions growing storage costsA 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.

Check yourself

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.