Fast cross-region disaster recovery and low-latency global reads

with Amazon Aurora Global Database

In this tutorial, you will learn how to create an Amazon Aurora Global Database deployment that spans multiple AWS regions and replicates your data with no impact on performance. Aurora Global Database provides disaster recovery from region-wide outages and enables low-latency global reads.

Amazon Aurora is a MySQL and PostgreSQL-compatible relational database that combines the performance and availability of traditional enterprise databases with the simplicity and cost-effectiveness of open source databases.

An Aurora Global Database consists of a primary AWS region —where your data is mastered— and multiple read-only secondary AWS regions where the data is replicated. Your writes go to the primary database, but you can read from any region and benefit from low latency.

This tutorial will use Amazon Aurora with MySQL compatibility. 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.

Prerequisites

An Amazon Aurora DB cluster consists of one or more DB instances and a cluster volume that manages the data for those DB instances. An Aurora cluster volume is a virtual database storage volume that spans multiple Availability Zones, with each Availability Zone having a copy of the DB cluster data. Two types of DB instances make up an Aurora DB cluster: a Primary DB instance, which supports read and write operations, and an Aurora Replica, which connects to the same storage volume as the primary DB instance and supports only read operations. Each Aurora DB cluster can have up to 15 Aurora Replicas located in separate Availability Zones. Aurora automatically fails over to an Aurora Replica in case the primary DB instance becomes unavailable.

In this tutorial, you will create an Aurora Global Database with a primary cluster in one region and a secondary cluster in a different region. Which regions to use is up to you. It is recommended that you have an application in each of the regions you will use. For example, if your Aurora Global Database will have a primary cluster in us-east-1 and a secondary cluster in eu-west-3, you should have an instance in us-east-1 and another one in eu-west-3.

Also, if you want to save time, for each of those regions you can create a Security Group allowing incoming connections from your instances. For example, you can create a security group with an inbound rule of type MYSQL/Aurora allowing TCP connections on port 3306 from the security group of your instances.

Finally, in order to test your Aurora Global Database (see Step 8), you will need a MySQL client. If your application instances are running Amazon Linux, installing a MySQL client can be as simple as running sudo yum install mysql, but the exact command depends on the OS you are running. If you are running Windows, you can download MySQL workbench instead.

About this Tutorial
Time 10 minutes                                           
Cost Less than $1
Use Case Databases
Products Amazon Aurora, Amazon RDS
Audience Database administrators, Developers
Level Intermediate
Last Updated June 3, 2019

Step 1: Accessing the Amazon RDS console

1.1 — Open a browser and navigate to Amazon RDS console. If you already have an AWS account, login to the console. Otherwise, create a new AWS account to get started.

1.2 — On the top right corner, select the region where you want to launch the primary Aurora DB cluster. For the purposes of this tutorial, we will use us-east-1 as the primary region and eu-west-1 as the secondary region.

Already have an account? Log in to your account

1.3 — Click on “Create database” in the Amazon Aurora window.

1.4 — Scroll down and click on “Try it now” in the Aurora Global Database window. If you don't see the “Try it now” option, click here.

Step 2: Engine options

2.1 — On Engine type, select “Amazon Aurora”.

2.2 — On Edition, select “Amazon Aurora with MySQL compatibility”.

2.3 — On Version, select the most recent MySQL version.

2.4 — On Database Location, select “Global”.

2.5 — Choose the “Production” template.

Step 3: Global database settings

3.1 — For the Global database identifier, type “global-database-1”.

Step 4: Primary region settings

4.1 — For the DB instance size, select a large instance (ending with .large).

4.2 — For Availability & durability, choose “Don't create an Aurora Replica”.

Note that having an Aurora Replica is recommended for production environments, as it allows you to scale reads and it gives you automatic failovers within the same region as your primary database. In this tutorial we are not adding an Aurora Replica just to keep the exercise simple.

Step 5: Connectivity

5.1 — Select the VPC where you want to create the database.

Note that once created, a database can't be migrated to a different VPC.

5.2 — Click on “Additional connectivity configuration”.

5.3 — Select the default value for Subnet group.

5.4 — On Publicly accessible, select “No”.

This means you will have to connect to the database from an EC2 instance within the same VPC.

5.5 — On VPC security group, select “Create new”. If you happen to have a security group that allows incoming TCP connections on port 3306, you can choose it instead.

5.6 — In New VPC security group name, type “global-database”.

5.7 — Leave the default value for Database port.

Step 6: Additional configuration

6.1 — Leave the default values for Database options, Backup, Monitoring, Log exports, Maintenance, and Deletion protection.

6.2 — Click on “Create database”.

While the instances are being created, you will see a banner explaining how to obtain your credentials. This is a good opportunity to save the credentials somewhere, as this is the only time you will be able to view this password.

6.3 — Click on “View credential details”.

6.4 — Save the username and password.

Step 7: Add a secondary region

7.1 — Select “global-database-1”.

7.2 — Click on “Actions > Add a region”.

7.3 — From the drop down, select a region.

7.4 — Repeat steps 4.1 to 5.7.

7.5 — Click on “Add region”.

Once the databases become available, proceed to step 8.

Step 8: Test your Aurora Global Database

8.1 — Click on your primary database.

8.2 — Copy the Writer endpoint.

Open two terminal windows, log into your instances in the primary and secondary regions, and use the mysql command line client to connect to the databases.

You can now create a database, create a table and write some records. Everything you write to the primary will be replicated in the secondary cluster.

8.3 — Connect to your primary database:

$ mysql -h endpoint -P 3306 -u admin -p

When prompted for a password, enter the password you saved in the step 6.6.

8.4 — Create a database and write some data.

mysql> CREATE database tutorial;
Query OK, 1 row affected (0.01 sec)

At this point you can use the tutorial database, create tables and add some records.

8.5 — Go to the secondary region.

8.6 — Click on your secondary database.

8.7 — Copy the Reader endpoint.

8.8 — Connect to your secondary database:

$ mysql -h endpoint -P 3306 -u admin -p

When prompted for a password, enter the password you saved in the step 6.6.

8.9 — Read some data:

mysql> USE tutorial;
Database changed

Now you can verify that the database has been replicated to the secondary database. If you created a table, you can write to the primary cluster and read the data from the secondary cluster.

Step 9: Failover to a secondary region

While the default Aurora cluster gives you failover capabilities within the region, Aurora Global Database allows you to failover to secondary cluster in a different region. It means your database survives even if a whole region becomes unavailable.

Performing a failover for an Aurora Global Database involves removing the secondary cluster from the original global database—thus turning it back into a regional cluster with full read-write capabilities—, then using it as the primary cluster in a new Aurora Global Database.

You can manually perform a failover by following the instructions below.

9.1 — Stop writing to the primary database.

9.2 — Select the secondary cluster.

9.3 — Click on “Actions > Remove from Global”.

9.4 — Confirm by clicking on “Remove and promote”.

9.5 — Configure your application to write to the newly promoted cluster.

9.6 — Still in the secondary region, select the Regional cluster.

9.7 — Click on “Actions > Create global database”.

9.8 — From the drop down, select a region.

9.9 — Repeat steps 4.1 to 5.7.

Step 10: Cleanup

To finish this tutorial, you will delete your Aurora Global Database. You can keep it around, but be aware that you will be incurring charges.

In order to delete your Aurora Global Database, go to the RDS Dashboard and follow these instructions:

10.1 — Select “Databases” on the left pane.

This will show you a list of all your Aurora DB clusters.

10.2 — Select a global database instance.

10.3 — Click on “Actions > Delete”.

10.4 — You will be asked if you want to create a final backup. That's usually a good idea, but it's not necessary for this tutorial. Select “No” and click on “Delete”.

10.5 — Select a global database cluster.

10.6 — Click on “Actions > Remove from Global”.

10.7 — Confirm by clicking on “Remove from global”.

10.8 — Select the Regional database cluster.

10.9 — Click on “Actions > Delete”.

10.10 — You will be asked if you want to create a final snapshot. That's usually a good idea, but it's not necessary for this tutorial. Select “No” and click on “Delete DB cluster”.

10.11 — Switch to the secondary region and perform steps 10.1 to 10.9.

10.12 — Select the global database.

10.13 — Click on “Actions > Delete”.

10.14 — Confirm by typing “delete me” and clicking on “Delete”.

The status of your cluster will change to “Deleting”.

Congratulations

You have created an Aurora Global Database with replication across regions. You have learned how to scale reads to other regions in order to benefit from lower latency, and you have performed a failover to a secondary region.

Was this tutorial helpful?

Thank you
Please let us know what you liked.
Sorry to disappoint you
Is something out-of-date, confusing or inaccurate? Please help us improve this tutorial by providing feedback.