A bucket lives in one region. If the region has a bad day, so does the data. Replication keeps a copy of every new object in a second bucket, usually in another region (cross-region replication); the same region also works.
market-docsus-east-1, versioned
new objects
replication roletrusted by s3.amazonaws.com
copies
market-docs-dreu-west-1, versioned
Three things must be in place:
- Versioning on both buckets.
- A role that trusts
s3.amazonaws.com, with permission to read the source and write to the destination. S3 does the copying, as itself, using that role. - A replication configuration on the source.
The configuration
json
{
"Role": "arn:aws:iam::123456789012:role/s3-replication",
"Rules": [{
"ID": "to-ireland",
"Status": "Enabled",
"Priority": 1,
"Filter": {},
"DeleteMarkerReplication": { "Status": "Disabled" },
"Destination": { "Bucket": "arn:aws:s3:::market-docs-dr-1bocwlg" }
}]
}sh
aws s3api put-bucket-replication --bucket market-docs-1bocwlg --replication-configuration file://replication.jsonFrom then on, every new object is copied within seconds to minutes. Objects that were already there are not copied.
Checking a copy
sh
aws s3api head-object --bucket market-docs-1bocwlg --key prices.csv --query ReplicationStatusOn the source, PENDING and then COMPLETED; on the copy in the other bucket, REPLICA. FAILED usually means the role cannot write to the destination.