If you want to store multiple copies of objects in your S3 buckets in different regions, S3 can be set to automatically replicate objects from a source basket to replica buckets around the world, increasing the performance and access latency of your applications.
It should be noted that if the objects you are replicating are publicly available over the Internet, such as a media bucket for uploaded content, you can simply use the AWS CloudFront CDN to cache content on edge locations anywhere.
How does replication work?
Replication basically runs when you upload or update an item in a bucket. You create a replication rule that defines the source and the goal. Objects that are uploaded to the source bucket are uploaded to the target bucket. For replication to work, you must enable versioning. This will increase storage costs slightly, depending on how much you overwrite data.
There are some restrictions. AWS does not replicate deleted items, so you must delete each copy manually. And while replication usually happens fairly quickly, it can take up to 15 minutes or more if you replicate large objects.
When an object is replicated, a metadata tag is inserted into the source object. All replicas will have
REPLICA tag and the source object will be tagged
COMPLETED. This means that you can have b-directional replication – two buckets with replication rules that point to each other. S3 does not replicate uploaded objects with the replica tag, otherwise you are stuck in an infinite replication loop.
This is called multi-master replication, but there is no system to ensure that items uploaded later will be replicated later. In this setting, it is possible for data to get out of sync if you update two objects at the same time, and it is possible to work on outdated data when they are synchronized from one master to another.
Set up replication
From the S3 Management Console, navigate to the source code. You must enable versioning under Properties:
When enabled, you can add a new replication rule under Management> Replication> Add Rule.
By default, it will replicate all objects, but you can set a filter if you want.
Select the destination bucket under Destination. You can also configure the storage class for the replica items and set the owner if you transfer accounts. There is also an option for “S3 Replication Time Control”, which guarantees that items will be replicated within 15 minutes, backed by a service level agreement.
On the next screen, you must select or create an IAM role for replication. The permissions are handled automatically, just enter a name.
Click “Next” and click “Save.” The rule should be active immediately; you can try uploading an item, and you should see it replicated to the destination bucket, then you will see the replication status tag change to