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)

Replication Instance là gì?

DMS không phải compute service để bạn chạy application như EC2/Lambda. Nhưng để migrate/replicate database, DMS vẫn cần một compute worker ở giữa source và target. Trong DMS Standard, worker đó gọi là replication instance.

Source DB  ──►  DMS Replication Instance  ──►  Target DB
              chạy replication engine
              đọc source / transaction logs
              buffer data
              apply changes vào target

Replication instance dùng để:

  • Kết nối source database và target database
  • Chạy replication task: full load, CDC, hoặc full load + CDC
  • Đọc transaction logs/redo logs để capture INSERT/UPDATE/DELETE
  • Buffer/cache khi source nhanh hơn target hoặc network/target bị chậm
  • Apply changes sang target theo thứ tự phù hợp
  • Ghi metrics/logs/checkpoint để theo dõi và resume migration

Vì vậy với DMS Standard, bạn phải chọn size cho replication instance, ví dụ:

dms.t3.medium
dms.r5.large
dms.r5.xlarge

Nếu chọn quá nhỏ → full load chậm, CDC lag, thiếu memory, task có thể fail. Nếu chọn quá lớn → tốn chi phí khi workload thấp.

📖 Nguồn: Working with an AWS DMS replication instance

Replication trong DMS nghĩa là gì?

Trong DMS, replication là quá trình DMS copy/sync dữ liệu từ source sang target. Nó không nhất thiết là native database replication như Oracle Data Guard.

Replication typeÝ nghĩaUse case
Full loadCopy dữ liệu hiện có từ source sang targetInitial migration
CDCCapture thay đổi mới phát sinh từ transaction logsContinuous sync
Full load + CDCCopy dữ liệu hiện có và đồng thời capture thay đổi mớiMinimal downtime migration
Oracle on-premises
   ├── Existing records      ──► Full load ──► RDS Oracle
   └── Transactional changes ──► CDC       ──► RDS Oracle

AWS DMS Serverless

AWS DMS Serverless = mode DMS không cần tự chọn/sizing replication instance như DMS Standard. AWS DMS ẩn phần compute worker bên dưới, tự tính toán, provision và scale replication resources dựa trên workload thực tế.

Dùng khi câu hỏi nhấn mạnh:

  • Full load + CDC nhưng workload/throughput dao động
  • Không muốn quản lý replication instance
  • Muốn compute tự động scale theo migration/replication workload
  • Cần migrate/replicate database với operational burden thấp hơn DMS Standard

📖 Nguồn: Working with AWS DMS Serverless

DMS Standard vs DMS Serverless

Tiêu chíDMS StandardDMS Serverless
ComputeChọn replication instance chạy replication engineChọn Min/Max DCU
SizingBạn tự estimate instance size (dms.r5.large, dms.r5.xlarge, ...)DMS tự compute/provision capacity
ScalingPhải monitor và resizeAutoscaling trong giới hạn cấu hình
Ops burdenCao hơnThấp hơn
Phù hợpWorkload ổn định, predictableWorkload dao động, muốn managed scaling
BillingTheo replication instancePay-for-use theo DCU đang dùng

DMS Capacity Unit (DCU)

Với DMS Serverless, bạn cấu hình Compute Config bằng:

SettingÝ nghĩa
MinCapacityUnitsSố DCU tối thiểu DMS provision; cũng là mức scale-down thấp nhất
MaxCapacityUnitsSố DCU tối đa DMS có thể provision; cũng là mức scale-up cao nhất
MultiAZTạo standby replica ở AZ khác để failover; AWS khuyến nghị bật nếu dùng CDC/ongoing replication

AWS định nghĩa 1 DCU = 2 GB RAM. DMS tính phí theo số DCU replication đang dùng.

📖 Nguồn: AWS DMS Serverless components - Compute Config

Replication phases trong DMS Serverless

DMS Serverless vẫn hỗ trợ các kiểu replication quan trọng của DMS:

Phase / TypeÝ nghĩaKhi nào dùng?
Full loadCopy dữ liệu hiện có tại thời điểm bắt đầu replicationInitial migration
CDC initialCopy các thay đổi xảy ra trong lúc full load đang chạyBắt kịp source DB sau full load
CDC ongoingTiếp tục replicate thay đổi khi chúng xảy raNear-zero downtime / continuous replication
Full load and CDCMigrate dữ liệu hiện có + thay đổi phát sinh trong quá trình replicationPattern hay gặp nhất khi migrate DB đang chạy
On-prem Oracle                        Amazon RDS for Oracle
┌──────────────┐                      ┌──────────────┐
│ Existing data│ ─── Full load ─────► │ Existing data│
│ Transactions │ ─── CDC ongoing ───► │ New changes  │
└──────────────┘                      └──────────────┘
        │                                      ▲
        └──── DMS Serverless tự scale DCU ────┘

Autoscaling hoạt động thế nào?

Sau khi replication ở trạng thái RUNNING, AWS DMS quản lý capacity của underlying resources để thích ứng với workload thay đổi.

  • Workload tăng vượt threshold → DMS có thể scale up replication resources
  • Workload giảm đủ lâu → DMS có thể scale down để tiết kiệm chi phí
  • Scaling bị giới hạn bởi MinCapacityUnitsMaxCapacityUnits
  • Serverless replication không autoscale down trong khi full load đang chạy

📖 Nguồn: Understanding autoscaling in AWS DMS Serverless

Supported endpoints

DMS Serverless hỗ trợ nhiều source/target, bao gồm Oracle ở cả hai phía:

Vai tròVí dụ supported endpoints
SourcesOracle, SQL Server, PostgreSQL-compatible, MySQL-compatible, MariaDB, MongoDB, Amazon S3, IBM Db2
TargetsOracle, SQL Server, PostgreSQL, MySQL-compatible, Amazon S3, Redshift, DynamoDB, Kinesis Data Streams, MSK, OpenSearch, Neptune

Ví dụ exam:

On-premises Oracle → Amazon RDS for Oracle
Existing data + continuous transactional changes
Data volume fluctuates
Wants automatic compute provisioning

=> AWS DMS Serverless replication
=> Replication type: Full load and CDC

Khi nào chọn DMS Serverless?

Keyword trong đềĐáp án nên nghĩ tới
"automatically provision compute resources"DMS Serverless
"workload fluctuates" / "spikes in transaction volume"DMS Serverless autoscaling
"existing records and ongoing changes"Full load + CDC
"Oracle on-premises to RDS for Oracle"DMS homogeneous migration/replication
"reduce replication instance management"DMS Serverless

Lưu ý dễ sai

  • DMS Serverless không phải Lambda: Lambda không phải managed CDC engine cho database transaction logs.
  • DMS Serverless không phải Glue: Glue phù hợp ETL/batch/data integration, không phải lựa chọn chính cho transactional CDC migration.
  • DMS Serverless không phải EC2 Auto Scaling: bạn không tự deploy DMS replication instance trên EC2 rồi scale bằng script; DMS quản lý replication resources.
  • Replication instance không phải app server: nó là worker managed bởi DMS để chạy replication engine, đọc source logs, buffer dữ liệu và ghi sang target.
  • Nếu target là cùng engine như Oracle → RDS Oracle: thường không cần SCT, vì đây là homogeneous migration.

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 hoặc Serverless Replication)Local machine (Desktop app)
CostPay for replication instance hoặc DMS Serverless DCUFREE

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)
DMS Serverless DCUPay-for-use theo DMS Capacity Units đang dùng
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
"Automatically provision compute resources"DMS Serverless
"Data transfer volume fluctuates"DMS Serverless

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)
  • DMS Serverless = DMS tự provision/scale replication resources, không cần tự chọn replication instance
  • Full load + CDC + workload dao động = DMS Serverless

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
"Existing data + ongoing changes + fluctuating volume"DMS Serverless Full load + 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