This is a serverless solution for multi-regio data replication that can help store consistent data across different regions.
The terraform template deploys a Lambda function, two DynamoDB in different regions, and the minimum IAM resources required to run the application.
When items are written or updated or deleted in the table in first region (e.g. us-east-1), the changes are sent to a stream. This pattern configures a Lambda function to poll this stream. When the function is invoked, it retrieves data from the payload containing the contents of the table item that has been written or updated or deleted in the table in the first region, then it makes changes in the table of the second region (e.g. us-west-2) based on the event type.
- Create an AWS account if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
- AWS CLI installed and configured
- Git Installed
- Terraform CLI installed and configured
-
Create a new directory, navigate to that directory, and clone the repository.
git clone [email protected]:saiaunghlyanhtet/multi-region-data-replication.git
-
Change directory to the project directory.
cd multi-region-data-replication
-
Build the Java Lambda Function jar file using Maven.
mvn clean package
-
From the command line, initialize terraform to to download and install the providers defined in the configuration.
terraform init
-
From the command line, plan the resouces in the configuration.
terraform plan -out plan.tfplan
-
From the command line, apply the configuration.
terraform apply plan.tfplan
-
During the prompts:
- Enter yes
When items are written or updated or deleted in the table in first region (e.g. us-east-1), the changes are sent to a stream. This pattern configures a Lambda function to poll this stream. When the function is invoked, it retrieves data from the payload containing the contents of the table item that has been written or updated or deleted in the table in the first region, then it makes changes in the table of the second region (e.g. us-west-2) based on the event type.
Everytime after having made changes in the table in the first region, those changes will be reflected in the table of the second region. You can also see the detailed logs in the cloudwatch log group for the lambda function.
-
Delete all deployed resouces.
terraform destroy
-
During the prompts
- Enter yes
-
Confirm all created resources are deleted.
terraform show