I would like to have a custom "under maintenance" page show up if my webservers on EC2 go down.
My current setup 2 A records on Route 53, using DNS Failover with a static page as the secondary and the ELB instance as the primary.
The problem with this is DNS caching - when the server first goes down, the default 502 error appears for a while for clients who were recently on the page. It takes around 5 minutes for our custom maintenance page to show up for them. When the servers come back up, it also takes around 5 minutes for the maintenance page to go away.
The first problem is more pressing for me - I don't want users to see a plain "502 Bad Gateway" message, ever. If they visit our site and things are broken or down, they should always see our custom maintenance HTML page, regardless of whether the ELB targets went down half a second ago or 10 minutes ago.
How can I make it so that if my ELB instance returns a 502, the users will automatically see a custom error page 100% of the time, so that they never see the default "502 Bad Gateway" error page?