Post Syndicated from Macey Neff original https://aws.amazon.com/blogs/compute/maintaining-a-local-copy-of-your-data-in-aws-local-zones/
This post is written by Leonardo Solano, Senior Hybrid Cloud SA and Obed Gutierrez, Solutions Architect, Enterprise.
This post covers data replication strategies to back up your data into AWS Local Zones. These strategies include database replication, file based and object storage replication, and partner solutions for Amazon Elastic Compute Cloud (Amazon EC2).
Customers running workloads in AWS Regions are likely to require a copy of their data in their operational location for either their backup strategy or data residency requirements. To help with these requirements, you can use Local Zones.
Local Zones is an AWS infrastructure deployment that places compute, storage, database, and other select AWS services close to large population and industry centers. With Local Zones, customers can build and deploy workloads to comply with state and local data residency requirements in sectors such as healthcare, financial services, gaming, and government.
Solution overview
This post assumes the database source is Amazon Relational Database Service (Amazon RDS). To backup an Amazon RDS database to Local Zones, there are three options:
- AWS Database Migration Service (AWS DMS)
- AWS DataSync
- Backup to Amazon Simple Storage Service (Amazon S3)
Figure 1. Amazon RDS replication to Local Zones with AWS DMS
To replicate data, AWS DMS needs a source and a target database. The source database should be your existing Amazon RDS database. The target database is placed in an EC2 instance in the Local Zone. A replication job is created in AWS DMS, which maintains the source and target databases in sync. The replicated database in the Local Zone can be accessed through a VPN. Your database administrator can directly connect to the database engine with your preferred tool.
With this architecture, you can maintain a locally accessible copy of your databases, allowing you to comply with regulatory requirements.
Prerequisites
The following prerequisites are required before continuing:
- An AWS Account with Administrator permissions;
- Installation of the latest version of AWS Command Line Interface (AWS CLI v2);
- An Amazon RDS database.
Walkthrough
1. Enabling Local Zones
First, you must enable Local Zones. Make sure that the intended Local Zone is parented to the AWS Region where the environment is running. Edit the commands to match your parameters, group-name makes reference to your local zone group and region to the region identifier to use.
aws ec2 modify-availability-zone-group \
--region us-east-1 \
--group-name us-east-1-qro-1\
--opt-in-status opted-in
If you have an error when calling the ModifyAvailabilityZoneGroup operation, you must sign up for the Local Zone.
After enabling the Local Zone, you must extend the VPC to the Local Zone by creating a subnet in the Local Zone:
aws ec2 create-subnet \
--region us-east-1 \
--availability-zone us-east-1-qro-1a \
--vpc-id vpc-02a3eb6585example \
--cidr-block my-subnet-cidr
If you need a step-by-step guide, refer to Getting started with AWS Local Zones. Enabling Local Zones is free of charge. Only deployed services in the Local Zone incur billing.
2. Set up your target database
Now that you have the Local Zone enabled with a subnet, set up your target database instance in the Local Zone subnet that you just created.
You can use AWS CLI to launch it as an EC2 instance:
aws ec2 run-instances \
--region us-east-1 \
--subnet-id subnet-08fc749671example \
--instance-type t3.medium \
--image-id ami-0abcdef123example \
--security-group-ids sg-0b0384b66dexample \
--key-name my-key-pair
You can verify that your EC2 instance is running with the following command:
aws ec2 describe-instances --filters "Name=availability-zone,Values=us-east-1-qro-1a" --query "Reservations[].Instances[].InstanceId"
Output:
$ ["i-0cda255374example"]
Note that not all instance types are available in Local Zones. You can verify it with the following AWS CLI command:
aws ec2 describe-instance-type-offerings --location-type "availability-zone" \
--filters Name=location,Values=us-east-1-qro-1a --region us-east-1
Once you have your instance running in the Local Zone, you can install the database engine matching your source database. Here is an example of how to install MariaDB:
- Updates all packages to the latest OS version
sudo yum update -y - Install MySQL server on your instance, this also creates a systemd service
sudo yum install -y mariadb-server - Enable the service created in previous step
sudo systemctl enable mariadb - Start the MySQL server service on your Amazon Linux instance
sudo systemctl start mariadb - Set root user password and improve your DB security
sudo mysql_secure_installation
You can confirm successful installation with these commands:
mysql -h localhost -u root -p
SHOW DATABASES;
3. Configure databases for replication
In order for AWS DMS to replicate ongoing changes, you must use change data capture (CDC), as well as set up your source and target database accordingly before replication:
Source database:
- Make sure that the binary logs are available to AWS DMS:
call mysql.rds_set_configuration('binlog retention hours', 24);
- Set the
binlog_formatparameter to “ROW“. - Set the
binlog_row_imageparameter to “Full“. - If you are using Read replica as source, then set the
log_slave_updatesparameter toTRUE.
For detailed information, refer to Using a MySQL-compatible database as a source for AWS DMS, or sources for your migration if your database engine is different.
Target database:
- Create a user for AWS DMS that has read/write privileges to the MySQL-compatible database. To create the necessary privileges, run the following commands.
CREATE USER ''@'%' IDENTIFIED BY '';
GRANT ALTER, CREATE, DROP, INDEX, INSERT, UPDATE, DELETE, SELECT ON .* TO
''@'%';
GRANT ALL PRIVILEGES ON awsdms_control.* TO ''@'%';
- Disable foreign keys on target tables, by adding the next command in the Extra connection attributes section of the AWS DMS console for your target endpoint.
Initstmt=SET FOREIGN_KEY_CHECKS=0;
- Set the database parameter
local_infile = 1to enable AWS DMS to load data into the target database.
4. Set up AWS DMS
Now that you have our Local Zone enabled with the target database ready and the source database configured, you can set up AWS DMS Replication instance.
Go to AWS DMS in the AWS Management Console, and under Migrate data select Replication Instances, then select the Create Replication button:
This shows the Create replication Instance, where you should fill up the parameters required:
Note that High Availability is set to Single-AZ, as this is a test workload, while Multi-AZ is recommended for Production workloads.
Refer to the AWS DMS replication instance documentation for details about how to size your replication instance.
Important note
To allow replication, make sure that you set up the replication instance in the VPC that your environment is running, and configure security groups from and to the source and target database.
Now you can create the DMS Source and Target endpoints:
5. Set up endpoints
Source endpoint:
In the AWS DMS console, select Endpoints, select the Create endpoint button, and select Source endpoint option. Then, fill the details required:
Make sure you select your RDS instance as Source by selecting the check box as show in the preceding figure. Moreover, include access to endpoint database details, such as user and password.
You can test your endpoint connectivity before creating it, as shown in the following figure:
If your test is successful, then you can select the Create endpoint button.
Target endpoint:
In the same way as the Source in the console, select Endpoints, select the Create endpoint button, and select Target endpoint option, then enter the details required, as shown in the following figure:
In the Access to endpoint database section, select Provide access information manually option, next add your Local Zone target database connection details as shown below. Notice that Server name value, should be the IP address of your target database.
Make sure you go to the bottom of the page and configure Extra connection attributes in the Endpoint settings, as described in the Configure databases for replication section of this post:
Like the source endpoint, you can test your endpoint connection before creating it.
6. Create the replication task
Once the endpoints are ready, you can create the migration task to start the replication. Under the Migrate Data section, select Database migration tasks, hit the Create task button, and configure your task:
Select Migrate existing data and replicate ongoing changes in the Migration type parameter.
Enable Task logs under Task Settings. This is recommended as it can help you with troubleshooting purposes.
In Table mappings, include the schema you want to replicate to the Local Zone database:
Once you have defined Task Configuration, Task Settings, and Table Mappings, you can proceed to create your database migration task.
This will trigger your migration task. Now wait until the migration task completes successfully.
7. Validate replicated database
After the replication job completes the Full Load, proceed to validate at your target database. Connect to your target database and run the following commands:
USE example;
SHOW TABLES;
As a result you should see the same tables as the source database.
MySQL [example]> SHOW TABLES;
+----------------------------+
| Tables_in_example |
+----------------------------+
| actor |
| address |
| category |
| city |
| country |
| customer |
| customer_list |
| film |
| film_actor |
| film_category |
| film_list |
| film_text |
| inventory |
| language |
| nicer_but_slower_film_list |
| payment |
| rental |
| sales_by_film_category |
| sales_by_store |
| staff |
| staff_list |
| store |
+----------------------------+
22 rows in set (0.06 sec)
If you get the same tables from your source database, then congratulations, you’re set! Now you can maintain and navigate a live copy of database in the Local Zone for data residency purposes.
Clean up
When you have finished this tutorial, you can delete all the resources that have been deployed. You can do this in the Console or by running the following commands in the AWS CLI:
- Delete target DB:
aws ec2 terminate-instances --instance-ids i-abcd1234 - Decommision AWS DMS
- Replication Task:
aws dms delete-replication-task --replication-task-arn arn:aws:dms:us-east-1:111111111111:task:K55IUCGBASJS5VHZJIIEXAMPLE - Endpoints:
aws dms delete-endpoint --endpoint-arn arn:aws:dms:us-east-1:111111111111:endpoint:OUJJVXO4XZ4CYTSEG5XEXAMPLE - Replication instance:
aws dms delete-replication-instance --replication-instance-arn us-east-1:111111111111:rep:T3OM7OUB5NM2LCVZF7JEXAMPLE
- Replication Task:
- Delete Local Zone subnet
aws ec2 delete-subnet --subnet-id subnet-9example
Conclusion
Local Zones is a useful tool for running applications with low latency requirements or data residency regulations. In this post, you have learned how to use AWS DMS to seamlessly replicate your data to Local Zones. With this architecture you can efficiently maintain a local copy of your data in Local Zones and access it securly.
If you are interested on how to automate your workloads deployments in Local Zones, make sure you check this workshop.

































































Amit Maindola is a Senior Data Architect focused on big data and analytics at Amazon Web Services. He helps customers in their digital transformation journey and enables them to build highly scalable, robust, and secure cloud-based analytical solutions on AWS to gain timely insights and make critical business decisions.

Prashant Agrawal is a Sr. Search Specialist Solutions Architect with Amazon OpenSearch Service. He works closely with customers to help them migrate their workloads to the cloud and helps existing customers fine-tune their clusters to achieve better performance and save on cost. Before joining AWS, he helped various customers use OpenSearch and Elasticsearch for their search and log analytics use cases. When not working, you can find him traveling and exploring new places. In short, he likes doing Eat → Travel → Repeat.
Hendy Wijaya is a Senior OpenSearch Specialist Solutions Architect at Amazon Web Services. Hendy enables customers to leverage AWS services to achieve their business objectives and gain competitive advantages. He is passionate in collaborating with customers in getting the best out of OpenSearch and Amazon OpenSearch
Utkarsh Agarwal is a Cloud Support Engineer in the Support Engineering team at Amazon Web Services. He specializes in Amazon OpenSearch Service. He provides guidance and technical assistance to customers thus enabling them to build scalable, highly available and secure solutions in AWS Cloud. In his free time, he enjoys watching movies, TV series and of course cricket! Lately, he his also attempting to master the art of cooking in his free time – The taste buds are excited, but the kitchen might disagree.

![Directory tree showing training dataset and model configuration structure]](https://d2908q01vomqb2.cloudfront.net/1b6453892473a467d07372d45eb05abc2031647a/2023/10/17/figure-3.jpg)







Mykhailo Kondak is a Database Engineer in the AWS Database Migration Service team at AWS. He uses his experience with different database technologies to help Amazon customers to move their on-premises data warehouses and big data workloads to the AWS Cloud. In his spare time, he plays soccer.
Illia Kravtsov is a Database Engineer on the AWS Database Migration Service team. He has over 10 years of experience in data warehouse development with Teradata and other massively parallel processing (MPP) databases.
Michael Soo is a Principal Database Engineer in the AWS Database Migration Service. He builds products and services that help customers migrate their database workloads to the AWS Cloud.




















Naveen Balaraman is a Sr Cloud Application Architect at Amazon Web Services. He is passionate about Containers, Serverless, Architecting Microservices and helping customers leverage the power of AWS cloud.
Karthik Prabhakar is a Senior Big Data Solutions Architect for Amazon EMR at AWS. He is an experienced analytics engineer working with AWS customers to provide best practices and technical advice in order to assist their success in their data journey.
Parul Saxena is a Big Data Specialist Solutions Architect at Amazon Web Services, focused on Amazon EMR, Amazon Athena, AWS Glue and AWS Lake Formation, where she provides architectural guidance to customers for running complex big data workloads over AWS platform. In her spare time, she enjoys traveling and spending time with her family and friends.

















Rana Dutt is a Principal Solutions Architect at Amazon Web Services. He has a background in architecting scalable software platforms for financial services, healthcare, and telecom companies, and is passionate about helping customers build on AWS.
Ranjith Rayaprolu is a Senior Solutions Architect at AWS working with customers in the Pacific Northwest. He helps customers design and operate Well-Architected solutions in AWS that address their business problems and accelerate the adoption of AWS services. He focuses on AWS security and networking technologies to develop solutions in the cloud across different industry verticals. Ranjith lives in the Seattle area and loves outdoor activities.
Justin Leto is a Sr. Solutions Architect at Amazon Web Services with specialization in databases, big data analytics, and machine learning. His passion is helping customers achieve better cloud adoption. In his spare time, he enjoys offshore sailing and playing jazz piano. He lives in New York City with his wife and baby daughter.










Kartikay Khator is a Solutions Architect on the Global Life Science at Amazon Web Services. He is passionate about helping customers on their cloud journey with focus on AWS analytics services. He is an avid runner and enjoys hiking.
Kamen Sharlandjiev is a Sr. Big Data and ETL Solutions Architect and Amazon AppFlow expert. He’s on a mission to make life easier for customers who are facing complex data integration challenges. His secret weapon? Fully managed, low-code AWS services that can get the job done with minimal effort and no coding.

Gaurav Sharma is a Specialist Solutions Architect(Analytics) at Amazon Web Services (AWS), supporting US public sector customers on their cloud journey. Outside of work, Gaurav enjoys spending time with his family and reading books.
Damon Cortesi is a Principal Developer Advocate with Amazon Web Services. He builds tools and content to help make the lives of data engineers easier. When not hard at work, he still builds data pipelines and splits logs in his spare time.