Skip to main content
Tutorial

Migrate from RDS MySQL to Aurora MySQL in near zero downtime

Introduction

Overview

In this tutorial, we will look at how to migrate from Amazon RDS MySQL to Amazon Aurora MySQL with minimal downtime. As with any database migration, there are several options. For migrating data from a MySQL DB Instance to an Amazon Aurora MySQL DB Cluster, we recommend to use a special type of node called an Aurora Read Replica for the source MySQL DB instance. Amazon RDS uses the MySQL DB engines' binary log replication functionality and updates made to the source MySQL DB instance are asynchronously replicated to the Aurora Read Replica. As replication lag between source DB instance and Aurora Read Replica approaches zero, redirect your client applications to the Aurora Read Replica, and make the Aurora Read Replica a standalone Aurora MySQL DB cluster. For more information, refer Amazon Aurora documentation.

The methodology and steps discussed in this tutorial are applicable to any application’s database that resides on Amazon RDS MySQL DB instance and needs to be migrated to Aurora MySQL DB cluster.

The tutorial is not within the free tier and will cost you less than $1 provided you follow the steps in the tutorial and terminate your resources at the end of the tutorial.

What you will learn

  • How to use RDS Read Replicas to migrate from RDS MySQL to Aurora MySQL with minimal downtime

  • How to promote a read replica to become the new standalone Aurora MySQL DB cluster

  • How to connect your application to the new DB cluster

Pre-requisites

  1. Existing AWS account, if you don’t have an AWS account then you can create new account to get started.

  2. Amazon EC2 Key Pairs are used to connect securely to your EC2 Linux-based instances using SSH. If you already have a key pair, you can reuse it for this tutorial. If you don’t have key pair then follow the instructions to create new key pair in your preferred region, in which you will complete this tutorial.

  3. It is recommended that you complete this tutorial in Default VPC. Each AWS account is automatically created with a Default VPC in each region, containing a basic network configuration, where resources can be provisioned in any of that region’s availability zones, and can have direct access to the Internet. In rare circumstances, customers can re- purpose these default VPCs, or delete them entirely. If you cannot find the default VPC in your account and region, you can recreate it by following the steps listed here.

Implementation

Beginner

10 - 20 minutes

Less than $1

Setup web application

1. Download the CloudFormation template

The CloudFormation.yaml Template on the GitHub page will launch an Amazon EC2 instance of type t2.micro with latest Amazon Linux 2 OS, bootstrap Apache/PHP, and install a simple address book web application. The template will also create an Amazon RDS MySQL database instance in free tier, i.e. of type db.t2.micro and with no Multi-AZ setup or read replicas. The WebTier Security Group will allow only SSH and HTTP connections to the web server (EC2 instance), and the DBTier Security Group will only allow the WebTier Security Group to initiate database connections to the RDS DB instance over the TCP port 3306.

Go to the Github link and download the files as shown.

Click the Code option and then click on Download ZIP. The zip folder will be downloaded by your browser.

Go to the downloaded folder location on your machine and then unzip the folder. You will have all files as shown above.

GitHub repository page showing file list, branch set to master, and a "Code" dropdown with options to clone or download as ZIP.

2. Open CloudFormation

Open the AWS CloudFormation console and sign in with your AWS account credentials. Choose the Region drop-down and select the appropriate AWS Region. This tutorial uses the US West (Oregon) Region. Click on Create stack.

AWS CloudFormation interface with a "Create stack" button to model and provision cloud infrastructure.

3. Create stack

Select Template is ready, and choose Upload a template file as the source template. Then, click on Choose file and upload the CloudFormation.yaml (downloaded in previous step). Click Next.

AWS CloudFormation "Create stack" interface showing step 1, where a template is prepared and specified by uploading a file named "CloudFormation.yaml."

4. Review stack details and create stack

Populate the form as with the values specified below, and then click Next:

  • Stack Name: A unique identifier without spaces

  • DBInstanceID: RDS DB instance identifier. It defaults to rdsdb

  • DatabaseName: Database name. It defaults to mydb

  • KeyName: The existing key pair in this account and region

  • LatestAmild: Don't change this parameter, it will install the latest Amazon Linux 2 OS AMI

  • MasterUsername: Choose subnet to deploy the instances

  • MasterPassword: Password for MySQL database access

  • SubnetID: Choose subnet to deploy the instances

  • VPC: Choose VPC (Above subnet should be of this VPC)

Note: The resources that are created here will be prefixed with whatever value you specify in the Stack Name. Please specify a value that is unique to your account.

Once you click Next, on the Stack Options page, accept all of the defaults and click Next.

On the Review page, click Create stack.

AWS CloudFormation "Specify stack details" page with fields for stack name, parameters like DBInstanceID, DatabaseName, KeyName, and VPC, and a "Next" button highlighted.

5. Wait for stack creation

At this point, you will be directed back to the CloudFormation console and will see a status of CREATE_IN_PROGRESS. Please wait here until the status changes to COMPLETE.

AWS CloudFormation interface showing a stack named "rds2aurora" with status "CREATE_IN_PROGRESS" and event details.

6. (Optional) Refresh status

You can click on the refresh icon to see the progress of resources creation.

A table of events showing timestamps, logical IDs, and statuses, with statuses including "CREATE_COMPLETE" and "CREATE_IN_PROGRESS."

7. View stack outputs

Once CloudFormation status changes to CREATE_COMPLETE, go to the Outputs section.

Make a note of the Output values from the CloudFormation environment that you have launched, as you will need them for the remainder of the lab.

For this tutorial setup, the values are:

AWS CloudFormation console showing a stack named "rds2aurora" with a status of "CREATE_COMPLETE" and outputs including an RDS DB instance endpoint and a webserver URL.

8. Open web application and choose RDS

Open a new browser tab and navigate to the web server interface by entering the EC2 instance’s Public DNS name (from preceding step) into the browser. You should see a website that looks like the example.

Click on the RDS tab.

Amazon Web Services RDS load test interface showing instance ID, availability zone, and current CPU load at 1%.

9. Enter database details

Enter the credentials and database name as shown. The RDS Endpoint name was noted in previous step Click the Submit button.

Amazon Web Services interface showing database connection fields for endpoint, database name, username, and password with a "Submit" button.

10. Verify connection and view configuration file

You will see a brief message of a connection attempt by the application to connect to the database on the RDS DB instance, as shown.

You will review the contents of file rds.conf.php

"Amazon Web Services page showing a command execution for MySQL and a message about writing configuration to rds.conf.php, with a redirect notice."

11. View address book

Upon successful connection completion, you will be redirected to a simple address book application displaying all of the information from the database.

A web interface displaying an address book with entries for Alice and Bob, including their phone numbers, email addresses, and options to edit or remove each contact.

12. (Optional) Test database operations

Feel free to play around with the address book and add/edit/remove content from your RDS database by using the Add Contact, Edit, and Remove links in the Address Book. The changes made to the address book in this tutorial are shown.

A web-based address book interface hosted on Amazon Web Services, displaying names, phone numbers, emails, and options to edit or remove contacts.

13. Connect to Instance

Navigate to the EC2 console, choose the EC2 instance (Webserver) and choose Connect.

AWS EC2 dashboard showing a running t2.micro instance named "WebServer" in the us-west-2c availability zone with its public and private IP details.

14. Choose a connection method

In the Connect to your instance dialog box, choose EC2 Instance Connect (browser-based SSH connection) and then choose Connect. A browser window opens displaying the EC2 instance command line interface (CLI).

"EC2 Instance Connect interface showing connection method options, with 'EC2 Instance Connect' selected and a 'Connect' button highlighted."