AWS load balancer and maintenance page
Asked Answered
A

4

27

I'm using AWS Load Balancer with 3 EC2 servers, and I'm trying to serve a Maintenance page when site is under maintenance.

This page need to return 503 HTTP code, because it is a proper code for a maintenance mode and will prevent possible problems with SEO.

When I return 503 code from any of my servers, Load Balancer makes it "Not In Service", and when all servers return 503, website returns a blank page (because all servers are disconnected).

My questions are:

1) Is there any way to serve a custom static page with a message for visitors from Load balancer if there is no healthy servers?

2) Or how to configure Load Balancer's Health Check that it will not consider 503 as a reason to mark server as "unhealthy"?

Thanks!

Alltime answered 2/9, 2015 at 1:4 Comment(4)
possible duplicate of How do you put up a maintenance page for AWS when your instances are behind an ELB?Genoese
@Genoese I think that's a good answer, but to a different question (how do you provide a fail whale page). It does not seem to meet the requirement here for 503 responses and would allegedly cause SEO issues.Claribelclarice
I can't use other DNS service, I already use the one from my CDN.Alltime
Rackspace allow you to display an HTML page of your choice if the member servers are out of action. If AWS can't do this, it is a pretty big failTechnology
C
13

You could implement an additional route in your app server, let's say /hcm (for health check maintenance), that always responds 200 OK. When it's time for maintenance, you programmatically modify the ELB health check to use the /hcm target which returns 200 OK rather than / or /index.html, which both return 503 Service Unavailable. Revert these changes when exiting maintenance.

Claribelclarice answered 2/9, 2015 at 1:52 Comment(2)
Another option is to make the healthcheck use TCP rather than HTTP. It is easier than customizing special routes and means that the load balancer will consider the instance as available as long as it can connect to the right port. Might not work in all situations but is perfect for me with just two fixed servers.Resistor
I'm not able to use TCP for the healthcheck, only HTTP and HTTPS are available to me.Teasley
L
30

I've been searching for a quick way to do this. We need to return a 503 error to the world during DB upgrade, but white list a few IPs of developers so they can test it before opening back up to public.

Found a one spot solution:: Go to the Loader Balancer in EC2 and select the load balancer you would like to target. Below, you should see Listeners. Click on a listener, and edit the rule. Create a rule like this:

My rule set up Now everyone gets a pretty maintenance page returned with a 503 error code, and only two IP addresses in the first rule will be able to browse to the site. Order is important, where the two IP exceptions are on top, then it goes down the list. The last item is always there by default.

Listener Rules for Your Application Load Balancer: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/listener-update-rules.html

Lynching answered 16/1, 2020 at 19:30 Comment(2)
For me this is better than handling it from EC2. I want my hands free to do any type of upgrade, including DB/EC2 etc. Thanks for sharing. 👌🏻Organon
This is a great solution. But it does not refresh the page in the browser. It's stuck on the last page and only generates 503 to the console as a response from the server. It only works if you refresh the page :(Intrusive
C
13

You could implement an additional route in your app server, let's say /hcm (for health check maintenance), that always responds 200 OK. When it's time for maintenance, you programmatically modify the ELB health check to use the /hcm target which returns 200 OK rather than / or /index.html, which both return 503 Service Unavailable. Revert these changes when exiting maintenance.

Claribelclarice answered 2/9, 2015 at 1:52 Comment(2)
Another option is to make the healthcheck use TCP rather than HTTP. It is easier than customizing special routes and means that the load balancer will consider the instance as available as long as it can connect to the right port. Might not work in all situations but is perfect for me with just two fixed servers.Resistor
I'm not able to use TCP for the healthcheck, only HTTP and HTTPS are available to me.Teasley
D
5

Might not meet your 503 requirement but a good option for this is using s3 and dns failover: https://aws.amazon.com/blogs/aws/create-a-backup-website-using-route-53-dns-failover-and-s3-website-hosting/

Drivein answered 2/9, 2015 at 7:49 Comment(2)
I can't use Route 53, I have to use a different DNS serviceAlltime
Your solution is for unplanned maintenance, not planned maintenance which is the OP's question. It's a good solution, but for a different problem, therefore downvoting.Anarchy
A
1

The load balancer will serve a 503 for you when you no longer have any healthy server behind it so you should not do anything special.

If you return anything but a 200 on the health check, ELB will take the machine out of the load balancer after it fails the configured number of health checks.

So to recap, you can potentially serve 503 from your app when in maintenance, but you have to return 200 for health checks all the time. If you don't care about the content of the page, you can simply remove the machines from the load balancer (or fail health checks) and the LB will do the right thing for you.

Absonant answered 2/9, 2015 at 4:40 Comment(1)
LB returns a blank page with a 503 code, but I need to show a custom message to visitors during the maintenance mode. How can I configure LB to return it?Alltime

© 2022 - 2024 — McMap. All rights reserved.