6 min to readCloud Services

How to use DMS for continuous replication from MySQL to Aurora

hristo-ivanov-contact
Hristo IvanovSenior Cloud Infrastructure Engineer
how-microsoft-security-suite-delivers-getty-1243367408-blog-hero

In today's data-driven world, maintaining real-time data synchronization across multiple databases is crucial for ensuring high availability, disaster recovery, and enabling real-time analytics. AWS Database Migration Service (DMS) is a powerful tool that simplifies the process of migrating and replicating databases to AWS. One common use case is continuously replicating data from a MySQL database to an Amazon Aurora cluster.

Continuous replication offers several benefits, including minimal downtime, up-to-date data across databases, and seamless integration with AWS services. This blog post will guide you through the step-by-step process of setting up AWS DMS for continuous replication from a MySQL database to an Aurora cluster. By the end of this guide, you'll have a solid understanding of how to configure and manage continuous data replication, ensuring your data is always current and reliable.

Scenario

We'll cover the prerequisites you need, how to configure your MySQL source database and Aurora target cluster, and the necessary steps to set up and run your DMS replication task. Let's dive in and get started on making your data replication seamless and efficient.

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image1

Prerequisites

  • MySQL database to act as a Source Database.
  • Amazon Aurora cluster to be set up for a Target Database.
  • AWS account access with necessary permissions.
  • Basic understanding of AWS services and MySQL.

We will use the following setup:

  • MySQL RDS instance
    • Instance type - db.t3.micro
    • 20 GB storage
    • Engine – MySQL 8.0.32
  • Aurora MySQL instance
    • Instance type – db.t3.medium
    • 100 GB storage
    • Engine – Aurora MySQL 3.05.2
  • DMS Replication Instance –
    • dms.t3.micro
    • 50 GB storage
    • Engine – 3.5.4

Steps:

  • Create RDS MySQL database (or use an existing one)
    • configure the RDS instance
  • Create Snapshot from the MySQL
  • Migrate snapshot to Create Amazon Aurora Cluster
  • Configure DMS
    • create replication instance
    • create source endpoint
    • create target endpoint
    • create migration task
  • Start Migration Task

The infrastructure

For the infrastructure we will need a source MySQL database which will be migrated to Aurora Cluster via a snapshot. This will keep our data with a minimum drift and the replication between source and target will be less, helping out with the database performance. Next, we will need a replication instance which will do the actual replication from the source to the target database. For this to work a source and target endpoints will have to be set and at the end we will need a migration task.

Step 1: Preparing the MySQL Source Database

Configure binary logging:

  • Ensure binary logging is enabled on the MySQL database.
  • Configure binary logging retention period

After creating our MySQL database, we must make sure we have several options enabled.

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image2

The database must have binary logging (log_bin) enabled. Binary logging is a feature that records all changes to the database (such as INSERT, UPDATE, DELETE statements, and changes to data structure like CREATE or ALTER commands). These logs are stored in binary log files, which are essential for several purposes like replication, point in time recovery and so on. Another important step is to check the retention hours for the binlog as usually it is Null, meaning the binary log files will be deleted.

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image3

After checking the configuration, we have added some dummy information to the database including tables, names, as seen below:

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image4

Step 2: Setting Up the Amazon Aurora Cluster

Create an Aurora cluster:

  • Create Snapshot from MySQL RDS instance
  • Migrate snapshot to Aurora Instance

Now, to set up our cluster we will use snapshot from our current MySQL database “swo-mysql-db", this way we will have prepopulated tables which is a requirement for MySQL. Another option would be to create cluster via read replica.

To achieve this, we will use the option Migrate Snapshot and select our desired specification:

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image5

Configure the instance by choosing instance type and VPC:

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image6

Choose security group, AZ and Certificate Authority. The example below uses the default values:

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image7

Choose parameter group and click migrate:

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image8

When you click on the "Migrate” button it will start creating the new Aurora Cluster that we have configured.

Step 3: Configuring AWS DMS

Next step is to create DMS peripherals which includes a Replication instance, source endpoint, target endpoint and a migration task:

  • Create a replication instance:
  • Create source and target endpoints:
    • Source endpoint (MySQL):
      • Configure the source endpoint for MySQL, including hostname, port, username, and password.
      • Test the connection to ensure it’s working.
    • Target endpoint (Aurora):
      • Configure the target endpoint for the Aurora cluster.
      • Test the connection to ensure it’s working.

Let’s start with the replication instance:

First, choose appropriate name and description:

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image9

Next, configure instance class, engine version and storage capacity. You can also choose whether to have high availability or not, in my case I used single availability zone:

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image10

To create a source endpoint, and since the instance is already in the AWS Account, we are using the “Select RDS DB instance”:

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image11

We would need to select source engine server name, port and provide the username and password, we are not using the SSL option as my information is made up and it will slow the replication.

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image12

After creation, test the source endpoint connection:

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image13

Repeat the steps for target endpoint.

Step 4: Creating a DMS Task

After the steps above are completed successfully, the migration task follows up.

To create a database migration task, we need to follow the task configuration and input the replication instance, source and target endpoint and for migration type we will use continuous replication thus selecting “replicate data changes only”

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image14

We would need to use custom CDC start mode and then select the “Specify log sequence number” to start the replication process from the specific time that we want. This can be seen in the example below:

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image15

When specifying a log sequence number, we will enable the replication to start from that specific log which was taken in the desired time.

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image16

For the LOB column settings, we have several options, to understand why we chose the specific one here is a short explanation.

Full LOB mode – AWS DMS migrates all LOBs from source to target regardless of size. In this configuration, AWS DMS has no information about the maximum size of LOBs to expect. Thus, LOBs are migrated one at a time, piece by piece. Full LOB mode can be quite slow.

Limited LOB mode – You choose the maximum LOB size for DMS to accept. That enables DMS to pre-allocate memory and load the LOB data in bulk. LOBs that exceed the maximum LOB size are truncated, and a warning is issued to the log file. This option allows you to gain significant performance over full LOB mode.

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image17

Table preparation we will leave do nothing as we do not want our information to be deleted from the database, also for LOB we choose Limited as it is the fastest, and the data validation is turned off.

For table mappings we will use the default value for a schema “%”

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image18
how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image19

The last step is to select when to start our migration task, choose Automatic. Manual can be used if you need to do pre-migration checks.

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image20

Step 5: Replication

The replication will continue until it is stopped manually. It is recommended to stop your applications first so that no more changes are made to the tables before stopping the replication.

how-to-use-dms-for-continuous-replication-from-mysql-to-aurora-image21

Conclusion

Using AWS Database Migration Service (DMS) for continuous replication from a MySQL RDS instance to an Aurora database provides a reliable and efficient solution for keeping your databases in sync. By leveraging DMS, you benefit from its ability to handle schema conversion, minimize downtime, and automate the replication process. This not only ensures a smooth transition to Aurora but also supports real-time data updates without manual intervention. As you have seen, setting up DMS for continuous replication is a straightforward process that requires configuring the source and target endpoints, creating the replication instance, and setting up tasks. With AWS DMS in place, you can ensure your Aurora instance is always up to date, making it a valuable tool for scaling, disaster recovery, or migrating workloads with minimal disruption to your operations.

Whether you're looking to scale your MySQL workloads or modernize your database infrastructure with Aurora, DMS provides the flexibility and reliability needed to meet your business's evolving demands.

Additional Resources:

https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_AuroraOverview.html

https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Welcome.html

https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html

https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_LogAccess.Concepts.MySQL.html

https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_LogAccess.MySQL.BinaryFormat.html

https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_LogAccess.MySQL.Binarylog.html

https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.MySQL.html

https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.LOBSupport.html

Neon lights against a black background

Unlock the Full Potential of Your AWS Database

Discover how SoftwareOne can help you streamline your database migration and optimize your AWS environment with expert support and proven solutions.

Unlock the Full Potential of Your AWS Database

Discover how SoftwareOne can help you streamline your database migration and optimize your AWS environment with expert support and proven solutions.

Author

hristo-ivanov-contact

Hristo Ivanov
Senior Cloud Infrastructure Engineer