AWS S3 Cross-Region Replication Error Fix
In this tutorial, you'll learn about AWS S3 Cross. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
You set up S3 Cross-Region Replication and objects are not replicating — the Replication status shows PENDING or FAILED, and CloudWatch metrics report Replication errors.
Step-by-Step Fix
1. Enable versioning on both buckets
# Check current versioning status
aws s3api get-bucket-versioning --bucket source-bucket
aws s3api get-bucket-versioning --bucket destination-bucket
# Enable versioning if disabled
aws s3api put-bucket-versioning --bucket source-bucket --versioning-configuration Status=Enabled
aws s3api put-bucket-versioning --bucket destination-bucket --versioning-configuration Status=Enabled
Expected output after enabling:
{
"Status": "Enabled"
}
2. Attach the correct Replication IAM role
// Wrong: incomplete permissions in replication role
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:ReplicateObject",
"Resource": "arn:aws:s3:::source-bucket/*]
}
]
}
// Right: complete permissions for replication
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetReplicationConfiguration",
"s3:ListBucket]
],
"Resource": "arn:aws:s3:::source-bucket"
},
{
"Effect": "Allow",
"Action": [
"s3:ReplicateObject",
"s3:ReplicateDelete",
"s3:ReplicateTags",
"s3:GetObjectVersionForReplication",
"s3:GetObjectVersionAcl]
],
"Resource": "arn:aws:s3:::source-bucket/*"
},
{
"Effect": "Allow",
"Action": [
"s3:ReplicateObject",
"s3:ReplicateDelete",
"s3:ReplicateTags]
],
"Resource": "arn:aws:s3:::destination-bucket/*"
}
]
}
3. Check Replication configuration
aws s3api get-bucket-replication --bucket source-bucket
Expected output:
{
"ReplicationConfiguration": {
"Role": "arn:aws:iam::123456789012:role/s3-replication-role",
"Rules": [
{
"ID": "replicate-all",
"Status": "Enabled",
"Priority": 1,
"Filter": {},
"Destination": {
"Bucket": "arn:aws:s3:::destination-bucket",
"StorageClass": "STANDARD]
},
"DeleteMarkerReplication": {"Status": "Disabled"}
}
]
}
}
4. View Replication metrics
aws cloudwatch get-metric-statistics \
--namespace AWS/S3 \
--metric-name ReplicationLatency \
--dimensions Name=DestinationBucket,Value=destination-bucket Name=RuleId,Value=replicate-all \
--start-time 2024-01-01T00:00:00Z \
--end-time 2024-01-15T00:00:00Z \
--period 3600 \
--statistics Average
Prevention
- Enable S3 versioning on both source and destination buckets before configuring Replication.
- Use the S3 Replication role created by the AWS console wizard to ensure correct permissions.
- Monitor Replication metrics via CloudWatch dashboards.
- Test Replication with a small file first before enabling on production buckets.
- Enable S3 Replication metrics for visibility into Replication status.
Common Mistakes with s3 cross region
- Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
- Using
returnto exit a function early instead of wrapping a pure value in the monad - Mixing let bindings with <- bindings in do notation, producing type errors
These mistakes appear frequently in real-world AWS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro