OnCallReadyStart learning

AWS Lesson 38.22 · AWS V: Data, Resilience & the Edge · 14 min read

S3 replication and Object Lock: copies elsewhere, copies nobody can delete

In plain words

S3 already keeps three copies of every letter in three buildings of one city, so a fire in one building loses nothing. Replication sends a copy of every new letter to a post office in another city, or one run by different people. Object Lock is a time-lock safe: once a letter is inside, nobody can take it out before the date. In governance mode someone holding a special key still can; in compliance mode nobody can, not even the owner.

Together they protect you from losing a whole city, from your own mistakes, and from a thief with your keys.

S3 replication and Object Lock: copies elsewhere, copies nobody can delete

S3 already stores every object in three AZs, so you will not lose it to a failed disk or AZ. You can still lose it to a Region-wide event, to a wrong aws s3 rm --recursive, or to someone with your credentials who wants you to pay. Replication keeps a second copy in another bucket, in another Region or account. Object Lock makes object versions undeletable for a retention period, even by the root user in compliance mode. Together they are the S3 half of a backup strategy.

Need to know: replication needs versioning on both buckets and an IAM role that S3 assumes. It copies new objects only (existing ones need S3 Batch Replication), keeps the same version ID, and by default does not replicate delete markers or version deletes. CRR = cross-Region, SRR = same Region. Object Lock works on versioned buckets: governance mode can be bypassed with a special permission, compliance mode cannot be shortened or removed by anyone, and a legal hold blocks deletion with no end date.

Replicate to another Region

oncall-lab-docs-111122223333 (eu-central-1) holds the shop's contracts and invoices. The DR copy goes to oncall-lab-docs-dr-111122223333 in eu-west-1:

$ aws s3api get-bucket-versioning --bucket oncall-lab-docs-111122223333 --query Status --output text
Enabled
$ aws s3api get-bucket-versioning --bucket oncall-lab-docs-dr-111122223333 --region eu-west-1 --query Status --output text
Enabled
$ cat ~/oncall-lab/labs/aws/try5/replication.json
{
  "Role": "arn:aws:iam::111122223333:role/lab-s3-replication",
  "Rules": [
    {
      "ID": "docs-to-dr",
      "Priority": 1,
      "Status": "Enabled",
      "Filter": {
        "Prefix": ""
      },
      "DeleteMarkerReplication": {
        "Status": "Disabled"
      },
      "Destination": {
        "Bucket": "arn:aws:s3:::oncall-lab-docs-dr-111122223333",
        "StorageClass": "STANDARD_IA"
      }
    }
  ]
}
$ aws iam get-role --role-name lab-s3-replication --query 'Role.AssumeRolePolicyDocument.Statement[0].Principal' --output text
s3.amazonaws.com
$ aws s3api put-bucket-replication --bucket oncall-lab-docs-111122223333 --replication-configuration file://$HOME/oncall-lab/labs/aws/try5/replication.json

The configuration names the role, and one or more rules: a filter (prefix or tags), a priority when rules overlap, the destination bucket, and optionally a different storage class for the copies (Standard-IA here: the DR copy is rarely read) or another account as owner. DeleteMarkerReplication is off, so deleting an object in the source does not delete the copy. That is what you want against mistakes and attackers.

$ aws s3api put-object --bucket oncall-lab-docs-111122223333 --key contracts/2026/acme-renewal.pdf --body /etc/hostname --query VersionId --output text
piRMkfx4x0dp5tM.CdgTZ2jJYS1gV82.
$ aws s3api head-object --bucket oncall-lab-docs-111122223333 --key contracts/2026/acme-renewal.pdf --query ReplicationStatus --output text
PENDING
$ sleep 20
$ aws s3api head-object --bucket oncall-lab-docs-111122223333 --key contracts/2026/acme-renewal.pdf --query ReplicationStatus --output text
COMPLETED
$ aws s3api head-object --bucket oncall-lab-docs-dr-111122223333 --region eu-west-1 --key contracts/2026/acme-renewal.pdf --query '[ReplicationStatus,StorageClass,VersionId]' --output text
REPLICA	STANDARD_IA	piRMkfx4x0dp5tM.CdgTZ2jJYS1gV82.
$ aws s3api head-object --bucket oncall-lab-docs-dr-111122223333 --region eu-west-1 --key contracts/2025/acme.pdf
aws: [ERROR]: An error occurred (404) when calling the HeadObject operation: Not Found

The new object went PENDING -> COMPLETED on the source and arrived as a REPLICA with the same version ID in eu-west-1. The contract uploaded before the configuration existed was not copied (404 Not Found): replication only acts on writes after it is configured. Copying what was already there is a Batch Replication job. A FAILED status (a role S3 cannot assume, missing permissions, a KMS key the role may not use) is not retried by itself either. Watch OperationsFailedReplication and ReplicationLatency (with Replication Metrics on), and use S3 Replication Time Control when you need a promise: 99.99% of objects within 15 minutes.

What replication does not protect against

  • A deleted version in the source is never replicated: the copy survives.
  • A delete marker is replicated only if you turn it on (some teams do, for a mirror that looks identical).
  • An overwrite is replicated: the destination gets the new version too. So replication is not a backup against bad writes; versioning (and lifecycle rules that keep noncurrent versions for a while) is.
  • Someone with permissions on both buckets can delete both. That is why the DR copy belongs in another account with its own admins, and why critical copies get Object Lock.

Object Lock: write once, read many

$ aws s3api create-bucket --bucket try-audit-111122223333 --create-bucket-configuration LocationConstraint=eu-central-1 --object-lock-enabled-for-bucket --query Location --output text
http://try-audit-111122223333.s3.amazonaws.com/
$ aws s3api put-object-lock-configuration --bucket try-audit-111122223333 --object-lock-configuration 'ObjectLockEnabled=Enabled,Rule={DefaultRetention={Mode=GOVERNANCE,Days=30}}'
$ aws s3api put-object --bucket try-audit-111122223333 --key 2026/09/audit.log --body /etc/hostname --query VersionId --output text
fpiExbS7.kkKsES7y9jPbrsF..x1.sVh
$ V=$(aws s3api head-object --bucket try-audit-111122223333 --key 2026/09/audit.log --query VersionId --output text)
$ aws s3api head-object --bucket try-audit-111122223333 --key 2026/09/audit.log --query '[ObjectLockMode,ObjectLockRetainUntilDate]' --output text
GOVERNANCE	2026-10-22T20:00:24+00:00
$ aws s3api delete-object --bucket try-audit-111122223333 --key 2026/09/audit.log --version-id $V
aws: [ERROR]: An error occurred (AccessDenied) when calling the DeleteObject operation: Access Denied because object protected by object lock.
$ aws s3api delete-object --bucket try-audit-111122223333 --key 2026/09/audit.log --query DeleteMarker
true

Object Lock is enabled when the bucket is created (it turns versioning on, and it cannot be turned off). A default retention applies to every new version. Deleting the version fails, but deleting the key works. It only adds a delete marker, which is harmless because the locked version is still there. Now the difference between the modes:

$ aws s3api delete-object --bucket try-audit-111122223333 --key 2026/09/audit.log --version-id $V --bypass-governance-retention --query VersionId --output text
fpiExbS7.kkKsES7y9jPbrsF..x1.sVh
$ V2=$(aws s3api put-object --bucket try-audit-111122223333 --key 2026/09/audit-final.log --body /etc/hostname --query VersionId --output text)
$ aws s3api put-object-retention --bucket try-audit-111122223333 --key 2026/09/audit-final.log --version-id $V2 --retention Mode=COMPLIANCE,RetainUntilDate=2027-01-31T00:00:00Z
$ aws s3api delete-object --bucket try-audit-111122223333 --key 2026/09/audit-final.log --version-id $V2 --bypass-governance-retention
aws: [ERROR]: An error occurred (AccessDenied) when calling the DeleteObject operation: Access Denied because object protected by object lock.

Governance mode can be bypassed by a principal with s3:BypassGovernanceRetention who asks for it explicitly: a safety net against mistakes, with an escape hatch. Compliance mode cannot be shortened or removed by anyone until the date, not even the root user. That is what regulations like SEC 17a-4 require, and what makes a backup ransomware-proof. Use it on purpose: a wrong date in compliance mode cannot be undone either. A legal hold (put-object-legal-hold --legal-hold Status=ON) blocks deletion with no end date until it is removed, for litigation. AWS Backup's Vault Lock (a later lesson) is the same idea for backups.

On the exam (SAA-C03 1.3 and 2.2, SOA-C03 2.3): "copy objects to another Region for DR / compliance / lower latency" = CRR (versioning on both, an IAM role); "aggregate logs from several buckets in one Region" = SRR; "replicate objects that already exist" = Batch Replication; "replication within 15 minutes, guaranteed" = RTC. "WORM / cannot be deleted by anyone, including root" = Object Lock in compliance mode; "protect against accidental deletes but allow admins to override" = governance mode (or MFA Delete on versioning).

In an interview: "How do you make sure S3 data survives a compromised admin account?" - "Replicate to a bucket in a separate account whose admins are different people, with DeleteMarkerReplication off. Lock the copies with Object Lock in compliance mode for the retention you need. Use versioning with noncurrent-version retention against overwrites, and alarm on replication failures and on changes to bucket policies."

You can now: configure cross-Region replication (versioning, role, rules, storage class), read replication status on both sides, explain what replication does and does not copy (existing objects, delete markers, version deletes, overwrites), and protect object versions with Object Lock in governance and compliance mode.

Why it helps

S3 is durable against hardware, but not against a Region-wide event, a wrong aws s3 rm --recursive, or someone with your credentials who wants a ransom. Replication and Object Lock are the S3 half of a backup strategy.

The details matter more than the feature names: replication copies only new objects, does not replicate deletes by default, but does replicate overwrites. A DR copy in the same account can be deleted by the same admin. Interviewers and auditors ask exactly these questions.

Commands in this lesson

aws cat sleep grep

FAQ

Does replication copy the objects that were already in the bucket?

No. Replication acts only on writes made after the configuration exists; an older object is simply missing in the destination (404). Copying what was already there is an S3 Batch Replication job. A FAILED status, such as a role S3 cannot assume or a KMS key the role may not use, is not retried by itself either.

If I delete an object in the source, is the copy deleted too?

Not by default. Deleting a key in a versioned bucket adds a delete marker, and delete markers are replicated only if DeleteMarkerReplication is enabled. Deleting a specific version is never replicated. An overwrite, however, is replicated: the destination gets the new version too, so versioning is what protects you from bad writes.

What does replication need to work?

Versioning on both buckets, an IAM role that S3 assumes with permission to read the source and write the destination (and use any KMS keys), and a configuration with rules: a filter, a priority when rules overlap, the destination bucket, and optionally a storage class for the copies or another account as owner. CRR crosses Regions, SRR stays in one.

What is the difference between governance and compliance mode?

Governance mode blocks deletes and retention changes, but a principal with s3:BypassGovernanceRetention who asks explicitly can still delete: a safety net with an escape hatch. Compliance mode cannot be shortened or removed by anyone until the date, not even the root user, which is what makes a copy ransomware-proof. A legal hold blocks deletion with no end date until removed.

How do I know replication is working?

head-object shows ReplicationStatus: PENDING then COMPLETED on the source, REPLICA on the copy, FAILED when something is wrong. With Replication Metrics on, watch OperationsFailedReplication and ReplicationLatency in CloudWatch. S3 Replication Time Control adds a promise that 99.99% of objects are copied within 15 minutes, with metrics to alarm on.

In an interview Mid

How do you make sure S3 data survives a compromised admin account?

Replicate to a bucket in a separate account whose admins are different people, with DeleteMarkerReplication off, so deletes in the source do not reach the copy. Lock the copies with Object Lock in compliance mode for the retention you need, so nobody, not even root, can delete them early. Keep versioning with noncurrent-version retention against overwrites, which replication would copy. Then alarm on replication failures and on changes to bucket policies, because an attacker usually starts there.

Also asked: What is the difference between S3 cross-Region and same-Region replication? · Is S3 replication a backup? Why or why not? · What does Object Lock compliance mode protect against?

Practise this lesson in the terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.