Showing a Maintenance Page to All but Specific IPs with AWS Application Load Balancer Listener Rules
Overview
A web service we run on AWS needed maintenance, so I’ve put together how I switched it into maintenance mode using the ALB.
Steps
Change the rules from the ALB Listener list.
- Note: This time only 2 ports were open, and since 80 forwards to 443, I only handled 443.
Then,
- Source IP = office IP (e.g.
11.22.33.44/32) → forward to the default TargetGroup, and “Save” - All source IPs other than the office IP (
0.0.0.0/0) → respond with a503text/htmlmaintenance message, and “Save”
With that, the office IP can access the site as usual, while everyone else is shown the maintenance page.
You can’t add multiple rules and save them all at once; you save them one rule at a time.
What Content-Types can be returned in the response?
You can also return things like application/json for the Content-Type, so I used this to pass a message when an API server was under maintenance.
A small caveat
The maximum length was 1024 characters ♪
Adding CSS to the response body would likely push it over the 1024-character limit, so instead I uploaded it to S3, made it public, and referenced it from there.

