1
votes

Aws CLoudfront not returning the error code returned by origin server, instead it retuning the different error code.

Here my origin server is AWS elb and i have configured all the paths(*) to elb origin in behaviour section of cloudfront.

When i hit http://xxxx.cloufront.net/path1 i am getting 404, and i am getting 401 when i hit same url directly on elb (http://elburl/path1)

401 is expected because the app (behind elb) expects auth header and since the header not there so it returns 401

For the above request, I can see the 401 error code in elb log and 404 error code in cloudfront log, which means elb returns 401 (returned by app)

Note: I didn't configured any custom error page in cloudfront.

1
There is no plausible explanation for this unless you have a Lambda@Edge Origin Response trigger rewriting that status code. CloudFront doesn't natively even support customizing 401 errors -- it only supports 400, 403, 404, 405, 414, 416, 500, 501, 502, 503, and 504. What's in the response body from CloudFront? Is it the correct body from your origin? What headers are returned in the response? Are you certain the request through CloudFront is appearing in the ELB logs? Is it a Classic balancer or an Application balancer?Michael - sqlbot
since it is expecting auth header, set one in cloudfront and try. Also check if the path in the Origin settings is set to / or empty.Varun Chandak

1 Answers

0
votes

You can have CloudFront return an object to the viewer (for example, an HTML file) when your Amazon S3 or custom origin returns an HTTP 4xx or 5xx status code to CloudFront.

Try setting error object.