# 🚀 Migrating to AWS : Database Migration using AWS DMS

## 📋 **Introduction**

Migrating databases from **on-premises** to **AWS** is a critical step in cloud adoption. **AWS Database Migration Service (DMS)** helps streamline this process by providing a **secure, scalable, and automated** solution for **full-load and ongoing replication** of databases.

Following **Phase 1 - Application Discovery & TCO Analysis**, we now move to **Phase 2: AWS Database Migration** to efficiently transition **MySQL databases** from an **on-premises** setup to **Amazon RDS (Relational Database Service)**.

---

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738696054924/78c0d974-40ba-4ade-9a4d-bf854c3f5f1f.png align="center")

## 📌 **Key Objectives of Phase 2**

✅ **Provision AWS RDS as the target database.**  
✅ **Create a DMS Replication Instance** to facilitate data migration.  
✅ **Configure Source & Target DMS Endpoints** for secure connections.  
✅ **Enable Binary Logs in MySQL** for ongoing replication.  
✅ **Execute AWS DMS Migration Task** for database replication.

By the end of this phase, the **on-prem MySQL database** will be **fully migrated** to AWS RDS, ensuring **data integrity, security, and scalability**.

---

## 📑 **Follow the GitHub Documentation for Full Details**

🔹 **GitHub Repo:** [AWS Migration Project](https://github.com/prafulpatel16/mgn-aws-project01/blob/master/README.md)  
📌 **Phase 2: AWS Database Migration**  
➡️ **Pre-Requisite:** [GitHub Link](https://github.com/prafulpatel16/mgn-aws-project01/blob/master/migration/B-Phase%202-AWS%20Database-migration/0.Pre-requisite.md)  
➡️ **Database Migration:** [GitHub Link](https://github.com/prafulpatel16/mgn-aws-project01/blob/master/migration/B-Phase%202-AWS%20Database-migration/1.Database-migration.md)  
➡️ **Troubleshooting:** [GitHub Link](https://github.com/prafulpatel16/mgn-aws-project01/blob/master/migration/B-Phase%202-AWS%20Database-migration/3.Troubleshooting.md)  

🔹 **🎥 Watch the Video Tutorial on YouTube**: [Click Here](https://youtu.be/RsjnwFSk6LU)

---

## 🌍 **On-Premises Database Overview**

Before migration, let’s understand the existing **on-prem** database setup:

📌 **Database Server Details**  
🔹 **Database:** MySQL 5.7  
🔹 **Operating System:** Ubuntu 24.04 LTS  
🔹 **Storage:** 8 GB SSD  
🔹 **Tables:** `obbs.tbladmin`, `obbs.tblbooking`, `obbs.tblcontact`, etc.  
🔹 **Replication Type:** **Full Load + Ongoing Replication (CDC)**

💡 **Challenges with On-Premises Databases:**  
❌ **High Maintenance Costs** – Requires manual upgrades and monitoring.  
❌ **Limited Scalability** – Hard to scale with increasing data load.  
❌ **Backup & Recovery Issues** – No automated snapshot capabilities.

✅ **Why AWS RDS?**  
✔️ Fully managed database with automated backups.  
✔️ High availability with Multi-AZ deployment.  
✔️ Auto-scaling capabilities for dynamic workloads.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738696439017/b15f2453-1f9c-4a2f-9982-fbad909f41de.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738696451351/43664643-fe8a-454f-bde5-41438f79b9a6.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738696458867/0dc8f32f-9bbd-45a4-bac5-609e18a4665c.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738696467724/190909a6-96cb-4103-9f31-3396604efba5.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738696475247/c5b092a6-bdca-4c4f-8724-16c795ebf4fe.png align="center")

---

## 🏗 **Step 1: Create Target RDS Database in AWS**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738695958958/45522fe3-8551-4ad9-b385-2d1c7bfdb148.png align="center")

📌 The **first step** is to **provision an Amazon RDS MySQL instance** as the **target database**.

### 🛠 **Steps to Create RDS Instance**

1️⃣ **Go to AWS Console → Amazon RDS → Create Database**  
2️⃣ **Select MySQL as Engine Type**  
3️⃣ **Choose Multi-AZ Deployment for High Availability**  
4️⃣ **Set Master Username & Password**  
5️⃣ **Configure Security Groups for Database Access**  
6️⃣ **Enable Automated Backups & Monitoring**  
7️⃣ **Click on Create Database**

📌 **Once the RDS instance is running, note the endpoint.**  
✅ Example: `database-1.cpioo8iee1me.us-west-2.rds.amazonaws.com`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738696596534/73d5c688-2dfb-4575-9f16-51094458c627.png align="center")

---

## 🚀 **Step 2: Create AWS DMS Replication Instance**

📌 AWS DMS Replication Instance acts as a **bridge** to replicate data from the **source MySQL database** to **Amazon RDS**.

### 🛠 **Steps to Create a DMS Replication Instance**

1️⃣ **Go to AWS DMS Console → Replication Instances → Create Replication Instance**  
2️⃣ **Choose Instance Type:** `dms.t3.medium` (for moderate workloads)  
3️⃣ **Set Storage:** 100 GB (adjust based on database size)  
4️⃣ **Select VPC & Security Groups:** Ensure RDS and On-Prem Server are accessible  
5️⃣ **Click Create Replication Instance**

📌 **Once the replication instance is available, proceed to configuring endpoints.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738696027049/ad274d61-600b-4cca-a121-6ac77584ef6a.png align="center")

---

## 🔄 **Step 3: Configure Source & Target Endpoints**

### 🔹 **Source Endpoint (On-Prem MySQL)**

1️⃣ **Go to AWS DMS Console → Endpoints → Create Endpoint**  
2️⃣ **Choose Source Type:** MySQL  
3️⃣ **Enter Source Database Endpoint:** `<on-prem-db-IP>:3306`  
4️⃣ **Enter Username & Password**  
5️⃣ **Test Connection → If Successful, Save Endpoint**

### 🔹 **Target Endpoint (Amazon RDS MySQL)**

1️⃣ **Go to AWS DMS Console → Endpoints → Create Endpoint**  
2️⃣ **Choose Target Type:** MySQL  
3️⃣ **Enter Amazon RDS Endpoint:** `database-1.cpioo8iee1me.us-west-2.rds.amazonaws.com`  
4️⃣ **Enter Username & Password**  
5️⃣ **Test Connection → If Successful, Save Endpoint**

✅ **With both endpoints successfully configured, we move to DMS Migration Task.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738696084074/b8f57957-be38-4e37-a9ee-ec70c74f7151.png align="center")

---

## 🚀 **Step 4: Execute DMS Migration Task**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738695984225/1e64fbec-b940-4341-9e91-d51191da45a3.png align="center")

📌 **Create a migration task in AWS DMS to transfer data from On-Prem MySQL to AWS RDS.**

### 🛠 **Steps to Create DMS Migration Task**

1️⃣ **Go to AWS DMS Console → Database Migration Tasks → Create Task**  
2️⃣ **Select Source & Target Endpoints**  
3️⃣ **Choose Replication Type:** `Full Load + Ongoing Replication (CDC)`  
4️⃣ **Enable Logging & CloudWatch Monitoring**  
5️⃣ **Click Start Migration Task**

📌 **DMS will now start migrating the data. Check CloudWatch logs for progress.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738696123320/41f432df-72e6-416a-ae5a-9aedbef19d62.png align="center")

Status: Created

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738696137030/46d0e539-c59d-43d4-88e9-be11a692a975.png align="center")

Status: Load Complete

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738696157309/114f65b4-de09-43ae-96b3-67aa1b44402a.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738696179086/9983dbdf-5f99-4458-8529-baf89331eb6c.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738696186465/d8fba581-3bb1-41e1-a07b-8fc50684458d.png align="center")

---

## ✅ **Step 5: Testing & Validation**

📌 **Once migration is complete, validate the database in AWS RDS.**

### 🛠 **Steps to Verify Data Migration**

1️⃣ **Connect to AWS RDS using MySQL Workbench or CLI.**

```bash
mysql -h database-1.cpioo8iee1me.us-west-2.rds.amazonaws.com -u admin -p
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738696298453/24896bac-7eb9-49c4-a1e5-4d688aa3263d.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738696309596/974e40e9-d38a-426a-867a-579a0142599d.png align="center")

2️⃣ **Check database and tables.**

```sql
SHOW DATABASES;
USE obbs;
SHOW TABLES;
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1738696322136/34ad604d-2f91-47b3-8f3b-1b77ba83b249.png align="center")

3️⃣ **Verify Data Consistency**

```sql
SELECT COUNT(*) FROM obbs.tbladmin;
```

✅ **Data successfully migrated from on-prem to AWS RDS!** 🎉

---

## 🎯 **Summary of Phase 2**

✅ **Provisioned AWS RDS MySQL as the Target Database.**  
✅ **Created AWS DMS Replication Instance for Data Transfer.**  
✅ **Configured Source & Target Endpoints for Secure Migration.**  
✅ **Executed DMS Migration Task for Full Load & Ongoing Replication.**  
✅ **Verified Data Consistency Post-Migration.**

📌 **Next Step:** **Phase 3 - Application Migration**

🔗 **GitHub Repo:** [AWS Migration Project](https://github.com/prafulpatel16/mgn-aws-project01/blob/master/README.md)  
🎥 **Watch on YouTube:** [Click Here](https://youtu.be/RsjnwFSk6LU)

🚀 **Stay tuned for more AWS migration insights!**  
#AWS #DMS #DatabaseMigration #CloudComputing #DevOps #RDS #AmazonWebServices
