You can try these steps to put up the maintenance page:
- Replicate your EB environment to create another one, call it something like app-environment-maintenance, for instance.
- Change the configuration for autoscaling and set the min and max servers both to zero. This won't cost you any EC2 servers and the environment will turn grey and sit on your list.
- This is a requirement, but we use CloudFront, as many people will for HTTPS, etc. CloudFront has error pages.
- Create a new S3 website hosting bucket with your error pages. Consider creating separate files for response codes, 503, etc. See #6 for directory requirements and routes.
- Add the S3 bucket to your CloudFront distribution.
- Add a new behavior to your CloudFront distribution for a route like /error/*.
- Setup error pages in Cloudfront to handle 503 response codes and point it to your S3 bucket route, like /error/503-error.html
Finally, you can use the AWS CLI to now swap the environment CNAME to take your main environment into maintenance mode. For instance:
aws elasticbeanstalk swap-environment-cnames \
--profile "$awsProfile" \
--region "$awsRegion" \
--output text \
- This would swap your api-prod environment into maintenance mode. It would cause the ELB to throw a 503 since there aren't any running EC2 instances and then CloudFront will catch the 503 and return your respective 503 error page.
- This is it, I know there are quite a few steps and I tried a lot of the suggested options out there including Route53 and many more, but all of these have issues with how they work with ELBs and CloudFront, etc.