Skip to Content

Versioning and replication

S3 versioning, delete markers and suspending versioning, then Cross-Region and Same-Region Replication, Batch Replication, delete markers and why replication doesn't chain.

Versioning

Versioning keeps every version of one key: the object uploaded before versioning has version null; each PUT adds a new version; a DELETE adds a delete marker that becomes the current version, so GET returns 404 while older versions can still be restored Versioning keeps every version of one key: the object uploaded before versioning has version null; each PUT adds a new version; a DELETE adds a delete marker that becomes the current version, so GET returns 404 while older versions can still be restored

Every overwrite and delete leaves the old version behind.

Versioning keeps every version of an object.

  • It's turned on at the bucket level. A bucket is unversioned (the default), versioning-enabled or versioning-suspended.
  • Uploading to the same key doesn't overwrite: it adds a new version, each with its own version ID (in practice a long random string; the diagram numbers them for clarity).
  • Deleting an object without a version ID doesn't remove anything: S3 adds a delete marker, which becomes the current version. GET now returns 404, but the older versions are still there. Delete the marker and the object is back.
  • Deleting a specific version ID removes that version permanently.

Why it's best practice:

  • protects against accidental deletes and overwrites (restore an older version);
  • makes it possible to roll back to a previous version.

Notes:

  • Objects stored before versioning was turned on have the version ID null.
  • Suspending versioning doesn't delete existing versions; new uploads just stop creating versions.
  • Versioning can't be turned off once enabled, only suspended.
  • Every version is stored and billed. Use lifecycle rules to expire old versions.

Replication

S3 replication: a source bucket in eu-west-1 copies new objects asynchronously to a bucket in the same Region (Same-Region Replication) and to a bucket in us-east-1 (Cross-Region Replication), which can be in another account; versioning must be on in both buckets S3 replication: a source bucket in eu-west-1 copies new objects asynchronously to a bucket in the same Region (Same-Region Replication) and to a bucket in us-east-1 (Cross-Region Replication), which can be in another account; versioning must be on in both buckets

Copy new objects to another bucket automatically.

S3 Replication copies objects from a source bucket to one or more destination buckets automatically.

  • Cross-Region Replication (CRR): the destination is in another Region.
  • Same-Region Replication (SRR): the destination is in the same Region.
  • Versioning must be on in both the source and destination buckets.
  • Buckets can be in different AWS accounts.
  • Copying is asynchronous: it usually takes seconds, but there's no guarantee. S3 Replication Time Control (RTC) promises 99.9% of objects within 15 minutes, for a fee.
  • S3 needs an IAM role that lets it read the source and write the destination.

Use cases:

  • CRR: compliance (a copy far away), lower-latency access for users in another Region, replication across accounts.
  • SRR: log aggregation from several buckets into one, live replication between production and test accounts.

What gets replicated

  • After replication is turned on, only new objects are replicated.
  • To copy existing objects, and objects that failed to replicate, use S3 Batch Replication.
  • Deletes:
    • Delete markers can be replicated, if that option is turned on.
    • Deletes of a specific version are never replicated, so a malicious delete in the source can't wipe the copy.
  • No chaining: if bucket 1 replicates to bucket 2, and bucket 2 replicates to bucket 3, objects created in bucket 1 are not copied on to bucket 3. Replicas aren't replicated again.
  • Two-way replication between two buckets is possible, for active-active setups.

Real-world examples

  • A hospital keeps patient images in eu-west-1 and replicates them with CRR to eu-central-1, to meet a rule that a copy must be in a second location.
  • A company collects application logs from ten buckets into one central bucket with SRR, for analysis.
  • A developer overwrites config.json with a broken version. With versioning on, they restore the previous version in seconds.

Exam tips

  • "Protect against accidental deletion or overwrite" → versioning (plus MFA Delete for more protection).
  • "Restore a deleted object" → delete the delete marker (or copy the previous version).
  • "Copy objects to another Region automatically", "disaster recovery for S3" → CRR.
  • "Aggregate logs from many buckets in the same Region" → SRR.
  • "Replicate objects that existed before replication was turned on" → S3 Batch Replication.
  • "Replication within a guaranteed time" → S3 Replication Time Control.

Common traps

  • "Turn on replication without versioning." Both buckets need versioning.
  • "Replication copies existing objects." Only new ones; use Batch Replication for the rest.
  • "A → B and B → C means A's objects reach C." Replication doesn't chain.
  • "Suspending versioning deletes old versions." It doesn't.

Hands-on lab: versioning and a delete marker

Goal: turn on versioning, overwrite and delete a file, and get it back.

Costs money

A few versions of a small file cost less than a cent. Any Region works.

Turn on versioning

Use your lab bucket. Properties → Bucket Versioning → Edit → Enable. Upload a text file note.txt containing v1.

Overwrite and delete

Change the file to v2 and upload it again with the same name. Then select note.txt and Delete it (type delete to confirm). The object list is empty.

Show versions and restore

Turn on Show versions. You see two versions of note.txt and a Delete marker on top. Select the delete marker and delete it (permanently delete). Turn off Show versions: note.txt is back, with v2 inside.

Expected result: a "deleted" file restored by removing its delete marker, with older versions still available.

Clean up: with Show versions on, delete every version of note.txt. Keep versioning on if you'll do the replication or lifecycle labs.

AWS documentation

On this page

Open notes

Spotted a mistake?

These notes are open source. Suggest a fix, or star the repo if they helped you.

Suggest an edit

For AI agents: llms.txt · llms-full.txt