Moving Rds Mysql DB To VPC
Moving Rds Mysql DB To VPC
July 2016
2016, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Notices
This document is provided for informational purposes only. It represents AWSs
current product offerings and practices as of the date of issue of this document,
which are subject to change without notice. Customers are responsible for
making their own independent assessment of the information in this document
and any use of AWSs products or services, each of which is provided as is
without warranty of any kind, whether express or implied. This document does
not create any warranties, representations, contractual commitments,
conditions or assurances from AWS, its affiliates, suppliers or licensors. The
responsibilities and liabilities of AWS to its customers are controlled by AWS
agreements, and this document is not part of, nor does it modify, any agreement
between AWS and its customers.
Contents
Introduction 1
Solution Overview 1
ClassicLink and EC2-Classic 1
RDS Read Replicas 2
RDS Snapshots 2
Alternative Approaches 3
AWS Database Migration Service (DMS) 3
Changing the VPC Subnet for a DB Instance 3
Migration Topology 4
Migration Steps 7
Step 1: Enable ClassicLink for Target VPC 7
Step 2: Set up a Proxy Server on an EC2-Classic Instance 8
Step 3: Use ClassicLink between Proxy Server and Target VPC 9
Step 4: Configure the DB Instance (EC2-Classic) 10
Step 5: Create a User on DB Instance (EC2-Classic) 11
Step 6: Create a Temporary Read Replica (EC2-Classic) 11
Step 7: Enable Backups on the Read Replica (EC2-Classic) 12
Step 8: Stop Replication on Read Replica (EC2-Classic) 13
Step 9: Create Snapshot from the Read Replica (EC2-Classic) 14
Step 10: Share the Snapshot (Optional) 15
Step 11: Restore the Snapshot in the Target VPC 17
Step 12: Enable Backups on VPC RDS DB Instance 19
Step 13: Set up Replication between VPC and EC2-Classic DB Instances 20
Step 14: Switch to the VPC RDS DB Instance 21
Step 15: Take a Snapshot of the VPC RDS DB Instance 22
Step 16: Change the VPC DB Instance to be Privately Accessible (Optional)22
Step 17: Move the VPC DB Instance into Private Subnets (Optional) 23
Conclusion 24
Contributors 24
Further Reading 25
Appendix A: Set Up Proxy Server in Classic 25
Abstract
Amazon Relational Database Service (Amazon RDS) makes it easy to set up,
operate, and scale a relational database in the cloud.
If your Amazon Web Services (AWS) account was created before 2013, chances
are you may be running Amazon RDS MySQL in an Amazon Elastic Compute
Cloud (EC2)-Classic environment, and you are looking to migrate RDS into an
EC2-VPC environment. This whitepaper outlines the requirements and detailed
steps needed to migrate Amazon RDS MySQL databases from EC2-Classic to
Amazon Virtual Private Cloud (VPC) with minimal down-time using RDS
MySQL Read Replicas and ClassicLink.
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
Introduction
Based on when an AWS account was created, Amazon EC2 instances and RDS
DB instances can be launched into either an EC2-Classic environment or an
EC2-VPC environment. EC2-Classic enables instances to run in a single, flat
network while VPC provides logical network isolation to run EC2 instances and
RDS DB instances. This logical network isolation closely resembles a traditional
network you might operate in your own data center, plus it has the benefits of
the AWS scalable infrastructure.
Solution Overview
ClassicLink is set up to enable communication between a VPC and RDS DB
instances in EC2-Classic. A Read Replica of the RDS DB instance in EC2-Classic
is created. Then, a snapshot of the DB instance is used to set up a Read Replica
in the VPC. A ClassicLink proxy in the VPC enables communication between the
source (also called the master) RDS DB instance in EC2-Classic and the target
VPC replica. Once the replica in the VPC has caught up with the master RDS DB
instance in EC2-Classic, updates against the master are stopped and the VPC
replica is promoted to master. At this point, the connection details in any
application that is reading or writing to the database are updated. The source
database remains fully operational during the migration, minimizing downtime
to applications.
Page 1
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
security groups and the EC2-Classic instance removes the need to use public IP
addresses or Elastic IP addresses to enable communication between these
platforms.
ClassicLink is available to all users with accounts that support the EC2-Classic
platform and can be used with any classic instance. Using ClassicLink and
private IP address space for migration ensures all communication and data
migration happens within the Amazon network without requiring a public IP
address for your RDS DB instance or an Internet Gateway (IGW) to be set up for
the VPC.
RDS Snapshots
This solution relies on Amazon RDS snapshots to initially create the target
MySQL DB instance in your VPC. Amazon RDS creates a storage volume
snapshot of your DB instance, backing up the entire DB instance and not just
individual databases. When you create a DB snapshot, you need to identify
which DB instance you are going to back up, and then give your DB snapshot a
name so you can restore from it later. Creating this DB snapshot on a Single-AZ
DB instance results in a brief I/O suspension that typically lasts no more than a
few minutes. Multi-AZ DB instances are not affected by this I/O suspension
since the backup is taken on the standby instance.
Page 2
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
Alternative Approaches
AWS Database Migration Service (DMS)
An alternative approach to migration is to use AWS Database Migration Service
(DMS). The AWS Database Migration Service can migrate your data to and from
most widely used commercial and open-source databases. The service supports
homogenous migrations such as Amazon RDS to RDS, as well as heterogeneous
migrations between different database platforms, such as Oracle to Amazon
Aurora or Microsoft SQL Server to MySQL. The source database remains fully
operational during the migration, minimizing downtime to applications that
rely on the database.
The database instance will not be available during the move. The move
could take between 5 to 10 minutes.
Page 3
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
Figure 1: Specifying a new subnet group (in a VPC) for a database instance
Migration Topology
This document focuses on how to use RDS Read Replica and snapshot
capabilities to migrate a RDS MySQL DB instance in EC2-Classic to a VPC over
ClassicLink. ClassicLink allows you to link your EC2-Classic instance to a VPC
in your account within the same region. After you've linked an EC2-Classic
instance, it can communicate with instances in your VPC using their private IP
addresses. However, instances in the VPC cannot access the AWS services
provisioned by the EC2-Classic platform using ClassicLink. So to migrate an
RDS database from EC2-Classic to VPC you must set up a proxy server. The
proxy server uses ClassicLink to link to the VPC with the Read Replica instance;
port forwarding on the proxy server allows communication between the source
RDS database in EC2-Classic and the target VPC RDS DB instance. This
Page 4
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
Figure 4 illustrates how the snapshot of the DB instance is used to set up a Read
Replica in the target VPC. A ClassicLink proxy in the VPC enables
communication between the source RDS DB instance in EC2-Classic and the
target VPC replica, as illustrated in Figure 5.
Page 5
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
Figure 5: Setting up replication between the Classic and VPC Read Replica
Figure 6 illustrates how updates against the master are stopped and the VPC
replica is promoted to master.
Page 6
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
Migration Steps
The following section lists the steps necessary to perform the migration.
Page 7
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
Set up appropriate security groups so the proxy server can communicate with
the RDS instance in EC2-Classic. In the following example, the proxy server and
the RDS instance in EC2-Classic are members of the same security group that
allows traffic within the security group.
Page 8
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
Page 9
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
Page 10
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
Page 11
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
You will then need to specify the network and security properties for the replica.
Page 12
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
Page 13
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
Using the show slave status command, save the replication status data in a
local file. You will need it later when setting up replication on the DB instance in
VPC.
Page 14
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
If you are migrating to a different account you will also set up a peering
connection between the local VPC and target VPC in remote account. Also, you
Page 15
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
will have to allow access to the security group that you used when you enabled
the ClassicLink between the proxy server and VPC.
Page 16
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
Page 17
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
Also, in the Networking and Security settings, Set Publicly Accessible to Yes
and select the target VPC and appropriate subnet groups to ensure connectivity
from the VPC RDS DB instance to the Classic Proxy Server.
Page 18
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
Page 19
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
Connect to the VPC RDS DB instance via a mysql client through the ClassicLink
proxy and set the Classic RDS DB instance as the replication master by issuing
the rds_start_replication command. Use the private IP address of the
EC2-Classic proxy server as well as the log position from the output above.
Page 20
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
+-------------------------+
| Message |
+-------------------------+
| Slave running normally. |
+-------------------------+
1 row in set (1.03 sec)
Query OK, 0 rows affected (1.03 sec)
Verify the replication status on VPC Read Replica via the show slave status
command.
At this point, the VPC will no longer be replicating data from the master. You
can now promote the replica by connecting to the VPC RDS instance via a
mysql client and issuing the mysql.rds_reset_external_master
command.
Page 21
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
+----------------------+
| message |
+----------------------+
| Slave has been reset |
+----------------------+
1 row in set (3.12 sec)
Query OK, 0 rows affected (3.12 sec)
You can now change the endpoint in your application to write to the VPC RDS
DB instance.
Page 22
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
RDS console, on the Instances page, select the DB instance and click Modify.
Under Network and Security, for Publicly Accessible, choose No.
Page 23
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
To change the private IP address of the RDS DB instance in the VPC you will
have to perform a scale up or scale down operation. For example, you could
choose a larger instance size. Once the IP address changes, you can scale again
to the original instance size.
Conclusion
This paper highlights the key steps to migrate RDS MySQL instances from EC2-
Classic to EC2-VPC environments using ClassicLink and RDS Read Replicas.
This approach enables minimal down-time for production environments.
Contributors
The following individuals and organizations contributed to this document:
Page 24
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
Further Reading
For additional help, please consult the following sources:
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_V
PC.html
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_V
PC.WorkingWithRDSInstanceinaVPC.html
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_M
ySQL.html
http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Net
working.html
http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-
classiclink.html
Page 25
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
env DAEMON=/usr/local/nginx/sbin/nginx
env PID=/usr/local/nginx/logs/nginx.pid
expect fork
respawn
respawn limit 10 5
pre-start script
$DAEMON -t
if [ $? -ne 0 ]
then exit $?
fi
end script
exec $DAEMON
worker_processes 1;
events {
worker_connections 1024;
}
stream {
server {
Page 26
Amazon Web Services Move Amazon RDS MySQL Databases to Amazon VPC using
Amazon EC2 ClassicLink and Read Replicas
listen 3306;
proxy_pass classicrdsinstance.123456789012.us-east-
1.rds.amazonaws.com:3306;
}
}
Page 27