Sub topic 15
Replicating objects across buckets and Regions
This chapter explains how S3 replication copies objects from one bucket to another, and where its behavior differs from what people expect. It assumes you know how to create buckets and enable versioning, can read IAM policy JSON, and are comfortable with the AWS CLI.
What replication does
Replication is a bucket-level feature. S3 copies new objects from a source bucket to a destination bucket asynchronously, based on rules you define. Two variants exist:
- Cross-Region Replication (CRR) copies to a bucket in a different Region.
- Same-Region Replication (SRR) copies to a bucket in the same Region.
Both use the same configuration. The only difference is where the destination bucket lives.
| Goal | Typical choice |
|---|---|
| Survive the loss of a whole Region | CRR |
| Put data closer to users or compute in another Region | CRR |
| Meet a rule that requires a copy in a second geography | CRR |
| Keep a separate copy under a different account or owner | SRR or CRR |
| Aggregate logs from several buckets into one | SRR |
| Run test or analytics workloads on a copy | SRR |
Replication is not a backup by itself. It copies mistakes as well as good data. Combine it with versioning, covered in the earlier versioning chapter, so you can recover earlier versions.
Requirements
Before S3 accepts a replication rule, these conditions must hold:
- Versioning is enabled on both the source and the destination bucket.
- S3 has an IAM role it can assume to read from the source and write to the destination.
- The source and destination buckets are different buckets. A rule cannot point at its own bucket.
- For CRR, the two buckets are in different Regions. For SRR, they are in the same Region.
If the destination belongs to another account, its bucket policy must also allow the role to replicate into it.
The replication role
S3 performs the copy on your behalf, so you create a role that S3 can assume. The trust policy names the S3 service:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "s3.amazonaws.com" },
"Action": "sts:AssumeRole"
}
]
}The permissions policy lets the role read from the source and write to the destination:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:GetReplicationConfiguration", "s3:ListBucket"],
"Resource": "arn:aws:s3:::my-example-bucket-123456789012"
},
{
"Effect": "Allow",
"Action": [
"s3:GetObjectVersionForReplication",
"s3:GetObjectVersionAcl",
"s3:GetObjectVersionTagging"
],
"Resource": "arn:aws:s3:::my-example-bucket-123456789012/*"
},
{
"Effect": "Allow",
"Action": ["s3:ReplicateObject", "s3:ReplicateDelete", "s3:ReplicateTags"],
"Resource": "arn:aws:s3:::my-example-bucket-123456789012-replica/*"
}
]
}If either bucket uses SSE-KMS, the role also needs kms:Decrypt on the source key and kms:Encrypt on the destination key. Objects encrypted with SSE-KMS are replicated only when the rule explicitly opts in, as described below.
Creating a replication rule
First enable versioning on the destination. The source already has it from the versioning chapter. The destination here is in eu-central-1:
aws s3api create-bucket \
--bucket my-example-bucket-123456789012-replica \
--region eu-central-1 \
--create-bucket-configuration LocationConstraint=eu-central-1
aws s3api put-bucket-versioning \
--bucket my-example-bucket-123456789012-replica \
--versioning-configuration Status=EnabledThen save the rule as replication.json. This rule replicates only objects under reports/ and stores the copies in Standard-IA:
{
"Role": "arn:aws:iam::111122223333:role/s3-replication-role",
"Rules": [
{
"ID": "replicate-reports",
"Status": "Enabled",
"Priority": 1,
"Filter": { "Prefix": "reports/" },
"DeleteMarkerReplication": { "Status": "Disabled" },
"Destination": {
"Bucket": "arn:aws:s3:::my-example-bucket-123456789012-replica",
"StorageClass": "STANDARD_IA"
}
}
]
}Apply it to the source bucket:
aws s3api put-bucket-replication \
--bucket my-example-bucket-123456789012 \
--replication-configuration file://replication.jsonReplace the account ID in the role ARN with your own. The rule uses the current schema, which has a Filter element, a Priority and an explicit DeleteMarkerReplication setting. A rule with an empty filter ("Filter": {}) matches every object in the bucket.
What gets replicated
Replication has narrower scope than many learners assume. Know these rules before you rely on it.
Only new objects
A rule applies to objects written after the rule is enabled. Objects already in the bucket are not copied. To copy existing objects, use S3 Batch Replication, which runs a one-time job against the objects that match a rule. Batch Replication also retries objects whose earlier replication failed.
No chaining
A replica is not replicated again. If bucket A replicates to B, and B replicates to C, objects written to A reach B only. To fan out, configure several rules on A with different destinations. Bidirectional setups between two buckets are possible and work because S3 does not send a replica back to where it came from.
Deletes
Deletes need careful handling:
- A delete without a version ID creates a delete marker on the source. Whether the marker is copied depends on
DeleteMarkerReplication. In the rule above it isDisabled, so the destination keeps the object visible. - A delete that names a specific version ID is never replicated. This protects the destination from malicious or accidental permanent deletes on the source.
What else does not carry over
- Lifecycle actions are not replicated. Expiration and transitions on the source do not run on the destination. Configure lifecycle on each bucket separately.
- Objects stored in Glacier Flexible Retrieval or Glacier Deep Archive must be restored before they can be replicated.
- Changes to a bucket's configuration, such as its policy or notifications, are not replicated.
- Metadata and tags are copied by default. The destination storage class is the one you set in the rule, or the source's class if you omit it.
Ownership and encryption
By default the replica is owned by the source bucket owner. For cross-account replication you can set an AccessControlTranslation of Owner: Destination so the destination account owns the copies. For SSE-KMS objects, add a SourceSelectionCriteria block that enables SseKmsEncryptedObjects, and name a destination KMS key in EncryptionConfiguration.
Checking replication status
Each source object carries a replication status you can read with head-object:
aws s3api head-object \
--bucket my-example-bucket-123456789012 \
--key reports/2026/report.csv \
--query ReplicationStatus| Status | Meaning |
|---|---|
| `PENDING` | S3 has accepted the object and has not finished copying it |
| `COMPLETED` | The copy reached the destination |
| `FAILED` | Replication did not succeed, often a permissions or KMS problem |
| `REPLICA` | Shown on the destination object, which is itself a replica |
Replication is asynchronous. Most objects arrive within minutes, but there is no guarantee by default. Replication Time Control (RTC) is an add-on that targets 15 minutes for 99.99 percent of objects and publishes metrics and events if copies fall behind. It costs extra.
Cost and design effects
Replication adds several charges. You pay for storage in the destination, for the PUT requests S3 makes there, and, for CRR, for inter-Region data transfer out of the source. Using a cheaper destination class such as Standard-IA reduces storage cost when the copy is rarely read. A narrow prefix or tag filter avoids paying to copy data that you do not need elsewhere.
Combine this with lifecycle rules from the earlier chapter. Because lifecycle does not replicate, a log bucket that expires objects after 365 days keeps its replica forever unless you add the same rule to the destination.
Common errors
- Enabling the rule and expecting old objects to appear. Use Batch Replication for those.
- Forgetting versioning on the destination. The
put-bucket-replicationcall fails. - Assuming a permanent delete on the source removes the replica. It does not.
- Chaining buckets and expecting the third bucket to receive data.
- Expecting lifecycle expiration to clean up the replica.
Exercise
A bucket in eu-west-1 replicates to a bucket in eu-central-1. You enable the rule today. A teammate deletes the object reports/old.csv by specifying its version ID, and you also have 5,000 objects uploaded last month. What happens to the permanent delete, and how do you get last month's objects into the destination?
Show answer
The permanent version delete is not replicated, so the destination still holds that version. Last month's objects were written before the rule existed, so they are not copied automatically. Run an S3 Batch Replication job for the rule to copy them.
Exercise
You replicate bucket A to bucket B, and B to bucket C, expecting a copy in all three. Objects uploaded to A never appear in C. Why, and what is the fix?
Show answer
Replicas are not replicated again, so objects written to A stop at B. Add a second rule on bucket A that targets C as its destination, using a distinct rule ID and priority.