How to manage website Failover using AWS Route 53 and a website hosted on an external domain

Scenario:

You have 2 websites:

  • “futureCloud.technology”, which is the primary website, is hosted on AWS EC2 Instance supported though an ELB(Elastic Load Balancer). Please keep in mind that GoDaddy.com is just the site registrar for the site name the site is not hosted there.
  • “mohdnaeem.wordpress.com”, which is the secondary/failover website is hosted on WordPress.com domain.
  • You are using Route 53 DNS service to resolve the domains.

Problem:

  • “futureCloud.technology” should be the primary website and should run when the EC2 Instance is healthy.
  • In case of failover the external website “mohdnaeem.wordpress.com” becomes the failover website. The requests for “futureClod.technology” should be routed to this external secondary website in case of the primary websites failure.

Solutions:

  • There can be various solutions. Let’s see them one by one.
  • Solution 1:
    • It is very primitive solution. Just write a domain forwarding rule on your registered websites domain manager panel. Any requests for “futureCloud.Technology” website will automatically be forwarded to “mohdnaeem.wordpress.com”
    • See snapshot below:
    • godaddy forwarding
    • Issue – this is a very basic solution and AWS Route 53 never comes into picture. It should be Amazon’s Route 53 which should dictate the failover logic not registrar.

 

  • Solution 2:
    • We will use AWS Route 53 to dictate the website failover from Primary to Secondary.
    • I am assuming the following:
      • That you created an AWS EC2 instance. (Ideally you create a couple of Instances hosting WordPress website and couple of MySQL Instances for your site to by highly available, fault tolerant and failover tolerant. But assuming that you have installed the WordPress website only on one LAMP server (Linux, Apache, MySQL and PHP). So that in case this primary website goes down then you can run the secondary from an external domain.)
      • That you already installed and configured ‘WordPress’ on the server.
      • That this site is configured behind an ELB (Elastic Load Balancer).
      • That your primary website is running on EC2 instance and failover secondary website (“mohdnaeem.wordpress.com”) is running on WordPress domain.
      • That you have registered a domain name ( say futureCloud.technology) at any domain registrar. I did at Godaddy.com)
    • So now let’s take the things forward from here.
      • First you will have to create a hosted zone exactly matching your registered domain name “futureCloud.technology” for your primary website in Route 53.
      • As you create a hosted zone in Route 53, it creates a couple of NS(Name Server) records. A SOA(Start of Authority) record. You will have to add a ‘A’ record for your EC2 website configured behind the ELB and another ‘A’ record for a S3 bucket (exactly matching the name of the registered website and configured as a static website). We will use this bucket for redirection.
      • See snapshot:
      • AWS Hosted ZOne futureCloud for EC2
      • AWS Hosted ZOne futureCloud for S3
  • Note down the 4 name servers and login to your registrars domain manager control panel(mine was GoDaddy.com) and add those 4 entries as Name Server records.
  • See snapshot:
  • godaddy nameservers
  • Now are configured to run your primary website, go ahead and open a browser and run the website – “futureCloud.technology”.
  • See snapshot:
  • AWS S3 buckets
  • Now you have to configure the failover so that when the EC2 instance is not healthy or not running your secondary failover website should run.
  • To do that first you have to create another bucket (exactly matching the name of the external failover website “mohdnaeem.wordpress.com”.
  • See snapshot:
  • S3 Redirect from futureCloud S3 to wordpress S3
  • In the bucket “futurecloud.technology” configure it as a website with a redirection rule to redirect to the other bucket “mohdnaeem.wordpress.com”.
  • See snapshot
  • S3 Redirect from futureCloud S3 to mohdnaeem.wordpress.com
  • In the bucket “mohdnaeem.wordpress.com” configure it as a website with a redirection rule to redirect to the external website “mohdnaeem.wordpress.com”.
  • See snapshot:
  • AWS S3 buckets
  • In case of EC2 is not healthy or not running the request will first reach “futurecloud.technology” bucket but it will redirect to the other bucket which is configured to redirect it to your external site.
  • Go to the Route 53 to configure another “hosted zone” which exactly matched the name of the external domain name (“mohdnaeem.wordpress.com”) and add an ‘A’ record as failover to the bucket by the same name.
  • As EC2 instance is down, the Route 53 first looks for s3 bucket “futureCloud.technology” but sees a redirection rule for bucket “mohdnaeem.wordpress.com” and which in turn has a redirection to the actual external website “mohdnaeem.wordpress.com”. The hosted zone entry thus maps this failover and redirects you to the external website.
  • Now go to the bowser and run “futureClod.technology”, but this time you will see that the website is redirected to “https://mohdnaeem.wordpress.com”
  • See snapshot:
  • external website running
  • All these redirection setting are being done because the AWS Route 53 is still not a very powerful DNS tool.

Thanks for reading this article. Please contact me in case you need any help. Please go to “About Us” page to view my details.

Advertisements