I have an ALB, containing Rules that forward requests to my private EC2s, hosted on AWS, and when I make a new deployment, I have a script in Lambda that turns off my ASGs and turns them back on. During this period when the ASGs are down and I try to access the website, the ALB responds with default 503 error, and I wanted to override that with my custom error page which I have placed in a separate S3 bucket.
I've followed the instructions posted in the answers section here: AWS ELB "sorry, site is down" page
So here's what I did:
- Created a CloudFront distribution with the Origin of ALB URL and Default (*) behavior to that ALB, with the CNAME: *.mywebsite.com
- Created an S3 bucket, uploaded my error page html under /error/index.html, and made it static hosted website.
- Added a new Origin in the existing CF, with the origin of static hosted S3 website URL.
- Added a new Behavior of /error/index.html Path Pattern and that S3 Origin.
- Added a new Error Page rule with HTTP Error Code 503, Page Response Path /error/index.html and HTTP Response Code 403 (I know 403 is wrong for this case but I just wanted to test if it would change the response code at least, but it did not).
However, when I try to access my website when EC2s are down, I still get the same default 503 error page. (I think this comes from ALB, right?)
About steps 2) and 3), I've also tried using the S3 Origin, instead of Custom Origin, but it still didn't work.
By the way, when I access the xxx.cloudfront.net URL of the distribution, I get my custom error page with 200 OK response (is this correct?).
What am I doing wrong?