AWS load balancer and maintenance page

后端 未结 4 1690
隐瞒了意图╮
隐瞒了意图╮ 2021-02-07 06:21

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, bec

相关标签:
4条回答
  • 2021-02-07 06:42

    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/

    0 讨论(0)
  • 2021-02-07 06:45

    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:

    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

    0 讨论(0)
  • 2021-02-07 06:49

    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.

    0 讨论(0)
  • 2021-02-07 06:55

    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.

    0 讨论(0)
提交回复
热议问题