Monday, January 18, 2016

AWS - Create Health Check and DNS Failover for Website

Let's say you have a website called "example.com" and primarily hosted on a server with IP 192.168.0.1, you also have a backup server with IP 192.168.0.2 in case primary host goes down. You are using AWS "Route 53" for your DNS record.

Without failover configuration, your DNS record for "example.com" probably looks like:
Name: example.com
Type: A - IPv4 address
Alias: No
TTL(Seconds): 300
Value: 192.168.0.1
Routing Policy: Simple

To create a automatic failover, you need to update your DNS record, also you need to create two additional record (One health check and one DNS record).

Create a health check:

1. In "Health checks" console, choose "Create health check"
2. Fill in the following information
Name: example.com
What to monitor: Endpoint
Specify endpoint by: IP Address
Protocol: HTTP
IP Address: 192.168.0.1
Port: 80
3. Keep evreything else default unless you want to change
4. Save this new health check

Route53 will now check the health of "example.com" by periodically requesting it and verifying that it returns a successful response.

Update existing record to the following:

Name: example.com
Type: A - IPv4 address
Alias: No
TTL(Seconds): 60
Value: 192.168.0.1
Routing Policy: Failover
Failover Record Type: Primary
Set ID: website-Primary
Associate with Health Check: Yes
Health Check to Associate: example.com

Note: TTL is set to 60 because we want shorten the cached time of the DNS record and allows quicker failovers

Create a new DNS entry:

Name: example.com
Type: A - IPv4 address
Aias: No
TTL (Seconds): 60
Value: 192.168.0.2
Routing Policy: Failover
Failover Record Type: Secondary
Set ID: website-Secondary
Associate with Health Check: No

Now your primary site is being health checked by Route53, and Route53 will automatically start sending traffic to backup server.

No comments: