Posted On: Dec 21, 2017
Starting today, Lambda@Edge enables you to customize error responses from your origin, by allowing you to execute Lambda functions in response to HTTP errors that Amazon CloudFront receives from your origin. This means Lambda@Edge functions associated with Amazon CloudFront origin response event will now be invoked for 4XX and 5XX error status codes, in addition to the currently supported 2XX (success) and 3XX (redirection) status codes.
Using this new capability, you can now use Lambda@Edge to access and override the error responses that CloudFront receives from your origin. You can add headers, issue redirects, or dynamically generate a response for your viewers based on the request attributes. For instance, if your origin is down or a connection cannot be established within the configured timeout value, viewers are currently served an HTTP 5xx error or the static custom error page configured in CloudFront. With this new feature, you can instead redirect viewers to a fail-over location, or generate a customized response within the Lambda function and return a 200 status code (OK). As another example, you can use this functionality to add HSTS security headers on error responses (in addition to 200 status code responses) to improve the overall website security.
There is no additional fee for using this new feature. To learn more about Lambda@Edge, visit the product page. For more information on how to use this new feature, please see the resources below:
- Learn how to customize error response in an origin response trigger.
- Examples showing redirects to another location and response generation with 200 status code (OK) in an origin response trigger.