On a good day everything works fine. Occasionally it is not a good day. Website is something that should be accessible on every day. With AWS that can be reached rather easily. I am going to discuss a solution that utilizes S3 and Route 53.
Steps are not super hard and there are lots of examples around. Yet, those might not cover all the aspects, at least I found that during my endeavour. Below is illustrated steps for basic case (HTTP, no LB).
Naturally we need a static website that will be used in a case of failure at the primary.
- Create bucket with the domain name. If your domain is example.com, then create bucket example.com.
- Upload static files to your bucket
- Turn S3 Website Hosting on
- Make uploaded files public (recap: select the file, go to “More”, -> Make public)
- Confirm that http://<example.com>.s3-website.<region>.amazonaws.com is working
The second AWS service is Route53. Following steps assumes that there is already a domain and hosted zone. First somekind of measurements have to be created and then we use to build automation to change the traffic from primary to secondary.
Create Health Check
- Choose a fancy name
- What to monitor: Endpoint
- Specify endpoint by : IP*
- Protocol: HTTP
- IP address: <ip address of your instance>
- Host name: <empty>
- Port: 80
- Path / : <what ever is preferred…>
- Advanced configuration -> Changes are not necessary required
- SNS notifications: if preferred.
*) Selecting Domain won’t fit here as Domain should be healthy all the time, just the routing should change according to the health check (either to Primary or Secondary).
Select your domain’s A-record and modify it
- Alias -> no
- Routing policy -> Failover
- Failover Record Type : Primary
- Set ID: Primary (or similar phrase whatever you prefer)
- Health Check: yes
Create new Record Set
- Alias -> yes
- Alias -> s3-website.<region>.amazonaws.com (Notice that there is no bucket name)
- Routing Policy -> Failover
- Failover Record Type: Secondary
- Set ID: Secondary (or similar phrase)
- Health Check: no
And that’s it pretty much. When Route 53 finds that Primary is not ok, then it routes traffic to Secondary. Steps are similar when loadbalancer is in the front of instances. Route53 can utilize loadbalancer’s health check, so configuring a Route 53 Health Check to check health of the instance is not required…