AWS Learning
Migration

AWS Database Migration Service (DMS)

Database Migration Service, SCT, 6Rs Migration Strategies, CDC

Tổng quan

AWS DMS (Database Migration Service) = Service giúp migrate databases từ on-premises, EC2, hoặc RDS sang AWS một cách dễ dàng.

┌─────────────────────────────────────────────────────────────────┐
│                    AWS DMS                                      │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  🎯 MỤC ĐÍCH: Migrate databases với minimal downtime            │
│                                                                 │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │                                                         │    │
│  │  Source DB                     Target DB                │    │
│  │  ┌──────────┐                  ┌──────────┐              │   │
│  │  │ Oracle   │                  │ Aurora   │              │   │
│  │  │ MySQL    │  ─────DMS─────►  │ RDS      │              │   │
│  │  │ SQL Srv  │                  │ DynamoDB │              │   │
│  │  │ PostgreSQL│                  │ Redshift │             │   │
│  │  └──────────┘                  └──────────┘              │   │
│  │  On-prem/EC2/RDS                AWS                     │    │
│  │                                                         │    │
│  └─────────────────────────────────────────────────────────┘    │
│                                                                 │
│  ✅ Source DB KHÔNG bị downtime trong khi migration             │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Key Features

FeatureMô tả
Minimal downtimeSource DB vẫn hoạt động bình thường khi migrate
Continuous replicationSync data liên tục (CDC - Change Data Capture)
HomogeneousCùng database engine (MySQL → MySQL)
HeterogeneousKhác database engine (Oracle → Aurora)
Schema conversionTích hợp với SCT để convert schema

6Rs Migration Strategies

[!IMPORTANT] 6Rs là các strategies để migrate workloads lên Cloud. Đây là kiến thức quan trọng cho exam!

┌─────────────────────────────────────────────────────────────────┐
│                    6Rs MIGRATION STRATEGIES                     │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  ┌──────────────────────────────────────────────────────────┐   │
│  │                                                          │   │
│  │  1. REHOST          "Lift and Shift"                     │   │
│  │     └─ Chuyển nguyên xi, không thay đổi gì                │  │
│  │     └─ VD: MySQL → MySQL trên EC2                         │  │
│  │                                                          │   │
│  │  2. REPLATFORM      "Lift and Reshape"                   │   │
│  │     └─ Thay đổi một chút để tận dụng cloud                │  │
│  │     └─ VD: MySQL → RDS MySQL (managed)                    │  │
│  │                                                          │   │
│  │  3. REPURCHASE      "Drop and Shop"                      │   │
│  │     └─ Mua solution mới (SaaS)                            │  │
│  │     └─ VD: CRM cũ → Salesforce                            │  │
│  │                                                          │   │
│  │  4. REFACTOR        "Re-architect"                       │   │
│  │     └─ Viết lại code để cloud-native                      │  │
│  │     └─ VD: Monolith → Microservices + Aurora Serverless   │  │
│  │                                                          │   │
│  │  5. RETIRE          "Tắt đi"                             │   │
│  │     └─ Không dùng nữa, decommission                       │  │
│  │     └─ VD: App cũ không còn users                         │  │
│  │                                                          │   │
│  │  6. RETAIN          "Giữ lại"                            │   │
│  │     └─ Giữ on-prem, không migrate                         │  │
│  │     └─ VD: Legacy system quá phức tạp để migrate          │  │
│  │                                                          │   │
│  └──────────────────────────────────────────────────────────┘   │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Chi tiết từng Strategy

StrategyÝ nghĩaEffortKhi nào dùng?
RehostLift & Shift - chuyển nguyên xiThấpMigrate nhanh, không muốn thay đổi
ReplatformThay đổi nhỏ để dùng managed servicesThấp-TBMuốn giảm operational burden
RepurchaseMua SaaS thay thếTBCó SaaS phù hợp, muốn outsource
RefactorViết lại cloud-nativeCaoCần tối ưu performance, scalability
RetireTắt bỏThấpApp không còn giá trị
RetainGiữ on-premKhông cóChưa sẵn sàng, quá phức tạp

Rehost vs Replatform (Hay hỏi trong exam!)

┌─────────────────────────────────────────────────────────────────┐
│                REHOST vs REPLATFORM                             │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  REHOST (Lift & Shift):                                         │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │  MySQL on-prem → MySQL trên EC2                         │    │
│  │                                                         │    │
│  │  • Y hệt như cũ, chỉ đổi chỗ                            │    │
│  │  • BẠN vẫn phải quản lý OS, patching, backup            │    │
│  │  • Operational burden: KHÔNG GIẢM                       │    │
│  └─────────────────────────────────────────────────────────┘    │
│                                                                 │
│  REPLATFORM (Lift & Reshape):                                   │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │  MySQL on-prem → RDS MySQL (managed)                    │    │
│  │                                                         │    │
│  │  • Vẫn là MySQL, nhưng giờ là MANAGED SERVICE           │    │
│  │  • AWS lo OS, patching, backup, scaling                 │    │
│  │  • Operational burden: GIẢM ĐÁNG KỂ ✓                   │    │
│  └─────────────────────────────────────────────────────────┘    │
│                                                                 │
│  → Câu hỏi "reduce operational burden" = REPLATFORM             │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

6Rs - Quick Reference

Keyword trong câu hỏiStrategy
"Move as-is", "no changes"Rehost
"Reduce operational burden", "managed service"Replatform
"Buy new software", "SaaS"Repurchase
"Rewrite", "cloud-native", "microservices"Refactor
"No longer needed", "decommission"Retire
"Keep on-premises", "not ready"Retain

Cách hoạt động

┌─────────────────────────────────────────────────────────────────┐
│                    DMS ARCHITECTURE                             │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  ┌──────────┐      ┌──────────────────┐      ┌──────────┐       │
│  │  Source  │      │  DMS Replication │      │  Target   │      │
│  │ Database │─────►│     Instance     │─────►│ Database  │      │
│  │          │      │                  │      │           │      │
│  └──────────┘      │  ┌────────────┐  │      └──────────┘       │
│                    │  │ Replication│   │                        │
│                    │  │    Task    │   │                        │
│                    │  └────────────┘   │                        │
│                    └──────────────────┘                         │
│                                                                 │
│  Components:                                                    │
│  • Source Endpoint: Connection info của source DB               │
│  • Target Endpoint: Connection info của target DB               │
│  • Replication Instance: EC2 chạy DMS software                  │
│  • Replication Task: Định nghĩa migrate cái gì, như thế nào     │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Workflow

  1. Create Replication Instance - EC2 chạy DMS engine
  2. Create Source/Target Endpoints - Connection settings
  3. Create Replication Task - Define migration settings
  4. Start Migration - Full load + CDC (ongoing replication)
  5. Cutover - Switch app sang target DB (minimal downtime)

Migration Types

1. Homogeneous Migration (Cùng engine)

Source và Target cùng database engine → Không cần convert schema.

┌─────────────────────────────────────────────────────────────────┐
│                HOMOGENEOUS MIGRATION                            │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  MySQL (on-prem)  ───DMS───►  RDS MySQL                         │
│  PostgreSQL       ───DMS───►  Aurora PostgreSQL                 │
│  Oracle           ───DMS───►  RDS Oracle                        │
│                                                                 │
│  → KHÔNG cần AWS SCT                                            │
│  → Schema và data types giống nhau                              │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

2. Heterogeneous Migration (Khác engine)

Source và Target khác database engine → CẦN convert schema trước.

┌─────────────────────────────────────────────────────────────────┐
│               HETEROGENEOUS MIGRATION                           │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  Step 1: Convert Schema (dùng AWS SCT)                          │
│  ┌──────────┐     ┌─────────┐     ┌──────────┐                  │
│  │ Oracle   │────►│   SCT   │────►│ Aurora   │                  │
│  │ Schema   │     │         │     │ Schema   │                  │
│  └──────────┘     └─────────┘     └──────────┘                  │
│                                                                 │
│  Step 2: Migrate Data (dùng AWS DMS)                            │
│  ┌──────────┐     ┌─────────┐     ┌──────────┐                  │
│  │ Oracle   │────►│   DMS   │────►│ Aurora   │                  │
│  │ Data     │     │         │     │ Data     │                  │
│  └──────────┘     └─────────┘     └──────────┘                  │
│                                                                 │
│  Examples:                                                      │
│  • Oracle → Aurora PostgreSQL                                   │
│  • SQL Server → Aurora MySQL                                    │
│  • Oracle → DynamoDB                                            │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Supported Databases

Sources (Nguồn)

CategoryDatabases
On-premisesOracle, SQL Server, MySQL, PostgreSQL, MariaDB, SAP, MongoDB
AWSRDS (all engines), Aurora, S3, DocumentDB
CloudAzure SQL, Azure MySQL, Azure PostgreSQL

Targets (Đích)

CategoryDatabases
RelationalRDS, Aurora, Redshift, Oracle, SQL Server, MySQL, PostgreSQL
NoSQLDynamoDB, DocumentDB, Neptune
Data LakeS3 (Parquet, CSV, JSON)
StreamingKinesis Data Streams
SearchOpenSearch Service

AWS Schema Conversion Tool (SCT)

AWS SCT = Tool convert database schema từ một engine sang engine khác.

┌─────────────────────────────────────────────────────────────────┐
│                    AWS SCT                                      │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  🎯 Converts:                                                   │
│     • Tables, Views, Indexes                                    │
│     • Stored Procedures, Functions                              │
│     • Triggers, Sequences                                       │
│     • Data types                                                │
│                                                                 │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │                                                         │    │
│  │  Oracle PL/SQL        SCT         Aurora PostgreSQL     │    │
│  │  ┌──────────────┐    ─────►      ┌──────────────┐        │   │
│  │  │ CREATE TABLE │               │ CREATE TABLE │         │   │
│  │  │ VARCHAR2     │    Convert    │ VARCHAR      │         │   │
│  │  │ NUMBER       │    ─────►     │ NUMERIC      │         │   │
│  │  │ PROCEDURE    │               │ FUNCTION     │         │   │
│  │  └──────────────┘               └──────────────┘         │   │
│  │                                                         │    │
│  └─────────────────────────────────────────────────────────┘    │
│                                                                 │
│  📊 Assessment Report:                                          │
│     • % code có thể auto-convert                                │
│     • % code cần manual fix                                     │
│     • Estimated effort                                          │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

SCT Features

FeatureMô tả
Assessment ReportPhân tích độ phức tạp của migration
Auto-convertTự động convert ~80-90% schema
Manual fixesHighlight code cần sửa manual
Data extraction agentsExtract data từ data warehouses

DMS vs SCT

AWS DMSAWS SCT
PurposeMigrate DATAConvert SCHEMA
When to useMọi database migrationChỉ khi heterogeneous migration
OutputData trong target DBSQL scripts cho schema
Runs onAWS Cloud (Replication Instance)Local machine (Desktop app)
CostPay for replication instanceFREE

Khi nào dùng cái nào?

┌─────────────────────────────────────────────────────────────────┐
│                    DECISION TREE                                │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  Source và Target cùng DB engine?                               │
│               │                                                 │
│        ┌───────┴───────┐                                        │
│        │               │                                        │
│       YES             NO                                        │
│        │               │                                        │
│        ▼               ▼                                        │
│   Dùng DMS        Dùng SCT + DMS                                │
│   (không cần       (SCT convert schema,                         │
│    SCT)             DMS migrate data)                           │
│                                                                 │
│  Examples:                                                      │
│  MySQL → RDS MySQL        = DMS only                            │
│  Oracle → Aurora MySQL    = SCT + DMS                           │
│  SQL Server → PostgreSQL  = SCT + DMS                           │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

Use Cases

1. On-Premises to AWS

Data Center                      AWS
┌──────────┐                     ┌──────────┐
│ Oracle   │ ───DMS + SCT───►   │ Aurora   │
│ Database │                     │ PostgreSQL│
└──────────┘                     └──────────┘

2. Cloud to Cloud

Azure                            AWS
┌──────────┐                     ┌──────────┐
│ Azure    │ ───────DMS───────► │ RDS      │
│ MySQL    │                     │ MySQL    │
└──────────┘                     └──────────┘

3. Consolidation

Multiple DBs                     AWS
┌────────────────────────────────────────────┐
│ MySQL    │ ─────┐
└──────────┘                                 │
                  │               ┌──────────┐
┌──────────┐      ├───DMS───────►│ Aurora    │
│ PostgreSQL│─────┤               │ MySQL    │
└──────────┘      │               └──────────┘

┌──────────┐      │
│ Oracle   │ ─────┘
└──────────┘

4. Continuous Replication (CDC)

On-Premises (still running)      AWS (for analytics)
┌──────────┐                     ┌──────────┐
│ MySQL    │ ───CDC ongoing────► │ Redshift │
│ (OLTP)   │                     │ (OLAP)   │
└──────────┘                     └──────────┘

   App vẫn chạy                  Analytics queries

Pricing

ComponentPricing
Replication InstancePer hour (like EC2)
StoragePer GB-month
Data TransferStandard AWS data transfer rates
SCTFREE

Instance sizing

SizevCPUMemoryUse case
dms.t3.micro21 GBTesting
dms.t3.medium24 GBSmall workloads
dms.r5.large216 GBProduction
dms.r5.xlarge432 GBLarge production

Exam Tips

[!IMPORTANT] DMS = Migrate DATABASE với minimal downtime. SCT = Convert SCHEMA khi khác engine.

Keyword → Answer

Keyword trong câu hỏiĐáp án
"Migrate database to AWS"AWS DMS
"Minimal downtime migration"AWS DMS
"Continuous replication"AWS DMS (CDC)
"Convert Oracle to Aurora"AWS SCT (schema) + DMS (data)
"Same engine migration"DMS only
"Different engine migration"SCT + DMS

Key Points

  • DMS = Migrate DATA
  • SCT = Convert SCHEMA (FREE, runs locally)
  • Homogeneous (same engine) = DMS only
  • Heterogeneous (different engine) = SCT + DMS
  • Source DB không downtime khi migration
  • CDC = Change Data Capture (continuous sync)

Common Scenarios

ScenarioSolution
"Migrate MySQL to RDS MySQL"DMS only
"Migrate Oracle to Aurora PostgreSQL"SCT + DMS
"Keep data synced during migration"DMS with CDC
"Migrate to data lake (S3)"DMS to S3
"Migrate data warehouse to Redshift"SCT (data extraction) + DMS

Tài liệu tham khảo