AWS application load balaner supports setting up a custom response for specific domain. If you need a easier method to serve a maintnace message from ALB you need to inject a new rule with fixed response. The fixed response can be a 5xx status code wtih custom html. To add a custom rule using AWS CLI, you need to have AWS CLI installed with the right permission and need to create a couple of JSON files such as one for creating a new listener ule and another one to delete the rule when you are done with the website maintenace.
Step 1: create a directory and the following two files:
Add the below code to the actions-fixed-response.json file. Make sure to update the content of your ALB fixed response message for the maintenace page.
The contents for the conditions-pattern.json will be as below. Replace the domain name to match your custom domain name.
Step 2: take a note of your listener ARN that you need adding the rule to and run the command below:
aws elbv2 create-rule --listener-arn <listener arn> --priority 5 --conditions file://conditions-pattern.json --actions file://actions-fixed-response.json
Step 3: to delete the rule you can run the command below.
aws elbv2 delete-rule --rule-arn <rule-arn>