Issue
I would like to redirect users to a custom maintenance page at a different domain. My setup includes AWS load balancer and EC2's. If the EC2 behind the LB is not reachable, What rule I need to add at LB to check the status code and redirect to a maintenance page at different domain?
Solution
Route53 Failover with S3 is an option
I suggest that you can use Route53 to achieve this with failover
approach and maybe using a static website hosted on Amazon S3 for cost optimization.
Here are the main ideas:
- Create the Route 53 health check which is your main site health check. If the status is failed, it redirects your traffic to the failed-over endpoint.
- Create a record set for your primary endpoint which points to your main site endpoint and (Your ALB DNS) with
Failover
routing policy. - Create the failover endpoint which can be a static site (S3) or your maintenance page domain.
References:
Route53 Health-check with SNS & Lambda
You can use this feature as a standalone healh-check without affecting your domain setup as above. It will notify any status changes to a SNS topic and you can subscribe a Lambda function to help you updating your Load Balancer listener to redirect your traffic into another site.
Once setup properly, it creates an alarm for you to monitor your main site.
With Lambda function, you can use Boto3 (Python3) to update your Load Balancer based on 2 kind of events:
Unhealthy
: route traffic to another domainHealthy
: route traffic to your target group
References:
- https://aws.amazon.com/premiumsupport/knowledge-center/lambda-subscribe-sns-topic-same-account/
- https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elbv2.html#ElasticLoadBalancingv2.Client.modify_listener
Answered By - Binh Nguyen Answer Checked By - Gilberto Lyons (WPSolving Admin)