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.