Search code examples
amazon-s3amazon-cloudfront

Configuring Different Error Pages for different origins for the same Cloudfront distributions


We created a cloudfront distribution with 2 origins (1 s3 origin and 1 custom origin). We want the errors(5xx/4xx) from the custom origin to reach the client/user without modification but the error pages from s3 be served by cloudfront error pages configuration. Is this possible ? Currently Cloudfront does not support different custom error pages for different origin - if either of the origin returns an error, the same error page is served by cloudfront.


Solution

  • You can customize the error responses for your origins using Lambda@Edge.

    You will need to associate an origin-response trigger to the behavior associated with your origin.

    The origin-response is triggered after CloudFront receives the response from the origin:

    enter image description here

    This way you can add headers, issue redirects, dynamically generate a response or change the HTTP status code.

    Depending on your use case, you may have to customize for both origins.

    See also Lambda@Edge now Allows you to Customize Error responses From Your Origin.