Setup Maintenance Server with AWS Route 53

I recently migrated from Heroku to AWS.

With Heroku,

it was fairly easy to configure a maintenance page and turn on the maintenance mode during an upgrade or downtime. Run a command to put site in maintenance mode.

  1. heroku maintenance:on –app <appname>
  2. Create a static page in S3 or any other cloud service and configure heroku to use it.

Simple. Done.

With AWS,

out of the box solution that I could use was not available. I decided to do set this up using Route 53 WRR. I was already using Route 53 which is Amazon’s DNS Service, so this was as simple as adding another Record Set. Assuming you have already setup Route 53 with the main Record Set and are creating a second record set for the maintenance site.

Steps I took:

  1. Create a new AWS EC2 instance.
  2. Install Apache.
  3. Update the index.html with the maintenance message.
  4. Create an Elastic IP and assign to the instance.
  5. Create a Type A record Set Set Alias to No Set Value to the IP address in Step 4. Set ID and weight & Save.

Live Mode:

  • Record Set 1: Main record set pointing to Elastic Load balancer. Set the weight to 1.
  • Record Set 2: Second record set pointing to Maintence IP Address. Set the weight to 0, to prevent traffic to it.

Maintenance Mode:

  • Record Set 1: Main record set pointing to Elastic Load balancer. Set the weight to 0.
  • Record Set 2: Second record set pointing to Maintence IP Address. Set the weight to 1.

It take about 5 minutes or so to take effect.

To make this repeatable/scalable

  • I should image the Ec2 instance so I can recreate this maintenance server quickly.
  • I should write a script to do this toggling using Amazon api’s, rather then doing it manually each time. The script should be something like – <appname> mode:live – <appname> mode:maintenance