Handling Multi-Region fail-over with Amazon Route 53 : Tutorial

Availability of an AWS region can be disrupted due any region wide events such as natural disasters, un-planned service outages etc.

The disruption in the availability of a region can be of an extended length of time which makes cross-region replication and availability an important aspect of your architecture. This will ensure that applications are highly available.

Amazon Route53 ensures that your applications are available with minimal amount of downtime.

Let us see how we configure disaster recovery scenario using route53.

Prerequisites

  • A web application should already been deployed in two different regions in AWS – US-East-1 (N.Virginia) and US-West-1 (Oregon) in this tutorial
  • Test both the apps are in running condition by hitting their Public IP addresses

What we will do in this tutorial?

  • We will Configure a domain in Route 53 to send traffic to our primary region.
  • We will then Configure a Health Check on the primary region -> If the health check fails, traffic will be sent to the secondary region.
  • We will Test the fail-over by stopping the instance in the primary region and check if the traffic is routed to the secondary region!

Step 1: Check your applications running in two regions

  • Go to EC2 > Instances and check your application ” for example “WEB APP -1” in region 1 that is US-EAST-1 (N Virginia)
  • Copy the IPv4 Public IP (shown in the bottom-right) and paste it into a text document for future reference.
  • This is the IP address of your Primary web server. You will configuring your domain to point to this instance by default.
  • Make a note of your Region, displayed in the top-right corner of the screen. This is the Region of your Primary web server.
web app 1 running in us-east-1
  • Now let us see the same Web app deployed in our secondary region i.e US-WEST-2 (Oregon)
  • Do the same, make sure it is running and click on the instance and copy the IPv4 Public IP and make note of it.
  • This is the IP address of your Secondary web server. You will configuring your domain to point to this instance if the Primary web server fails.

Step-2: Configuring a Health Check

  • Let us create a health check that will check the heath of out primary web server.
  • AWS has health checkers located in multiple locations around the world that can test whether your website is accessible.
  • Go to Route 53 from AWS services
  • In the navigation pane, click Health checks.
  • Click Create health check.
  • In the Configure health check page, configure the following settings like Name of the health check as “check-1“, IP address of primary webserver you copied earlier
  • In the advanced Confgurations, give Request Interval as Fast (10 seconds), and Failure threshold as 2
  • Then click on – Create Health Check

Step 3: Configure your Domain in Route53

Let us configure our domain to point to our primary and secondary web servers.

  • Firstly create a domain if it is already not their for your app
  • Click the name of your domain.
  • Click Create Record Set.
  • We will now create a DNS A-record to point to your Primary web server.
  • An A-record resolves a domain name by returning an IP address.
  • We will also associate this Record Set with the Health Check wecreated earlier so that traffic will only be sent to your Primary web server if the Health Check indicates that the server is healthy.
  • In Create Record Set, configure the following settings as shown in below image: Name as www, TTL a 60 seconds , Value as Primary Web Server IP v4 address, Associate With Health Check as Yes
  • Failover Record Type as primary, give name of the health check as check-1 which you created earlier.
  • Then click on Create !
  • An A-record should be listed. If the newly created record does not immediately appear in the table, periodically click the refresh icon to update the table until it appears.

Now Let us create another Record Set for fail-over!

  • Click Create Record Set again for secondary web server
  • In Create Record Set, configure the following settings as shown in below image: Name as www, TTL a 60 seconds , Value as Secondary Web Server IP v4 address, Associate With Health Check as NO
  • Click Create
  • You are not associating this record with a Health Check because there is no third site available.
  • You can now check the status of your Health Check.
  • In the navigation pane, click Health checks.
  • Select check-1.
  • Click the Health checkers tab at the bottom of the page.
  • The health check is performed independently from multiple locations around the world, with each location requesting the page every 10 seconds.
  • Confirm that check-1 has a status of Healthy.

You have now configured your web application to fail-over across two regions.

Step 4: Check the DNS Resolution

Let us query DNS (Domain Name Service) to verify that Amazon Route 53 is correctly sending traffic to your Primary web server.

  • In the navigation pane, click Hosted zones.
  • Click the name of your domain
  • Click Test Record Set.
  • If the Test Record Set button is not visible, try making your window wider so that it appears.
  • In Check response from Route 53, configure the following settings as shown in below two pics:
  • Click Get response.
  • The DNS response will bow be tested, with the results appearing on the right side of the window.
  • Look at the Response returned by Route 53 value. Confirm that it is the same IP address as your Primary web server.
  • If correct IP address is not displayed, check the configuration again
  • The fact that the Domain resolved to the IP address of the Primary web server means that requests to your domain will be routed by default to that web server.

Step 5: Test the fail-over

Finally, let us verify that Amazon Route 53 correctly fails over to your Secondary web server if your Primary web server fails.

We will simulate a failure by manually stopping the instance in your primary region as shown in below image

  • Go to EC2 > Instances and stop the primary web server which is in us-east-1 and wait until the instance state changes to stopped.
  • Now go to Route 53.
  • Click Health checks.
  • Select check-1 and click the Health checkers tab
  • Wait until the status of check-1 is Unhealthy. If necessary, periodically click the refresh icon in the top-right corner.
  • The Health Check has now detected that your Primary web server has stopped responding.
  • It should now be directing DNS requests to the Secondary web server.

Test the fail-over

  • In the navigation pane, click Hosted zones.
  • Click your domain name.
  • In Check response from Route 53, configure the following settings as shown in image
  • Click on Get Response and you can see Response returned by Route53 which is now pointing to secondary web server

So this ends here, it is very simple to configure if your application is aready up and running in two regions!

Thanks!

If you have any doubts, please comment below.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s