CloudFront Error Pages Not Routing Properly.

0

I set up my CF with a function to return a dummy set of JSON data if my origin throws 404, 502 or 503 errors: https://wdgt.listen-up.app/dummy

However, when it does, the CF somehow routes back to the origin, instead of the above. https://wdgt.listen-up.app/nothing

why? I tried setting the function to both Viewer request and response.

asked a year ago328 views
1 Answer
0

You cannot use Viewer request to detect 4XX and above errors, because those are responses and at the time of Viewer request there is no response. Also you can't use Viewer Response for the 4XX and above errors as that is not supported on Functions.

If the origin returns an HTTP error of 400 and above, the CloudFront Function will not run.

Source: Status code and body

You can instead use the default custom error page to return your data instead. Find out more under Generating custom error responses -documentation.

profile pictureAWS
EXPERT
Toni_S
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions