DEV Community

Darshan
Darshan

Posted on

Zero-Downtime-Cross-Region-Database-Migration-using-AWS-DMS

Overview
This project demonstrates how to perform a zero-downtime database migration across AWS regions using:

AWS Database Migration Service (DMS)
Amazon RDS (MySQL)
AWS CloudFormation
The system uses Change Data Capture (CDC) to continuously replicate database changes, ensuring minimal downtime and real-time synchronization.

🎯 Key Features
βœ… Zero/near-zero downtime migration
πŸ”„ Real-time data replication using CDC
🌍 Cross-region migration (e.g., Mumbai β†’ Singapore)
⚑ Automated infrastructure setup
πŸ” Data validation and consistency

πŸ—οΈ Architecture

![Uploading image](...

πŸ” Workflow
Full data load from source to target
CDC captures real-time changes
DMS applies changes continuously
Target DB stays in sync
Cutover to target database
🧰 Tech Stack
AWS DMS
Amazon RDS (MySQL)
AWS CloudFormation
MySQL Workbench
βš™οΈ Step-by-Step Implementation
🟦 Step 1: Create Source Database (RDS - Region A)
Go to AWS Console β†’ RDS
Click Create Database
Select:
Engine: MySQL
Instance: db.t3.micro
Set username & password
Enable public access (for testing)
or (Use cloud formation code)

download the source-db.yaml from cloudformaton/ folder

open cloudformation in aws cli

click on create stack

select - choose an existing template

select - upload a template file

create stack

🟦 Step 2: Create Target Database (RDS - Region B)
Switch AWS region
Repeat same steps as source
or (Use cloud formation code)

use target-db.yaml file from cloudformation/ folder
🟦 Step 3: Enable CDC (IMPORTANT)
Create Parameter Group
Go to RDS β†’ Parameter Groups
Create new parameter group
Set:
binlog_format = ROW
binlog_row_image = FULL
Attach to source DB
Reboot database
Step 4: Create DMS Replication Instance
Go to DMS β†’ Replication Instances Click Create Select: Instance: dms.t3.medium

Step 5: Create Endpoints
Source Endpoint

Enter source DB details (endpoint of source RDS)

Test connection

Target Endpoint

Enter target DB details (endpoint of destination RDS)

Test connection

Step 6: Create Migration Task
Go to DMS β†’ Tasks β†’ Create Task Configure: Migration Type: Full Load + CDC (change data capture) Table Mapping: Schema: demo_db Table: users

Step 7: Start Migration
Start the task Monitor: Full load CDC status

Step 8: Validate Data
connect source-db RDS database to mysql workbeanch
username admin password - Password123!
endpoint is RDS database endpoint
do the same for target RDS database

Source: INSERT INTO users VALUES (1, 'test_user');

Source database:

Step 9: Test CDC
UPDATE users SET name = 'updated' WHERE id = 1;

πŸ‘‰ Changes should reflect in target DB instantly Target database :

Step 10: Cutover
Stop writes to source Ensure replication lag = 0 Switch application to target DB

Key Concepts
πŸ”Ή What is CDC?

CDC captures changes (INSERT, UPDATE, DELETE) from database logs and replicates them in real time.

πŸ”Ή What is Replication Instance?

It is the compute engine that:

Reads source DB
Processes data
Writes to target DB
πŸ”Ή What is DMS Task?

Defines:

What to migrate
How to migrate
When to migrate
Common Issues & Fixes
possible errors
Error 1236 (Binlog Not Found)

Cause: Old logs deleted

Fix:

Recreate task Start from beginning

CDC Not Working Fix: binlog_format = ROW binlog_row_image = FULL

Data Not Syncing Check task status Ensure CDC enabled

Cost Estimation
Service Cost RDS (2 instances) ~$1.6 DMS ~$2.4 Data Transfer ~$0.2 Total ~$4–5

Results
βœ… Zero downtime migration achieved
πŸ”„ Real-time replication working
πŸ“ˆ Data consistency maintained
🏁 Conclusion
This project demonstrates how AWS DMS with CDC enables seamless and reliable database migration with minimal downtime.

References
1.AWS DMS Documentation 2.AWS RDS Documentation 3.MySQL Binlog Documentation

Author
Darshan B

Top comments (0)