Search code examples
aws-lambdaamazon-cloudfrontaws-lambda-edge

Lambda@Edge viewer response function is not called on 4xx response


I have a Cloudfront distribution with a lambda@edge function. The function is called on viewer response event for all traffic. I noticed that when the response status code is 4xx, the function is not called. I found this page which provides an example for updating error statuses for origin response event. I wonder if this is also possible for viewer response.


Solution

  • CloudFront does not invoke edge functions for viewer response events when the origin returns HTTP status code 400 or higher.

    -https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/edge-functions-restrictions.html#edge-function-restrictions-all

    Logically The HyperText Transfer Protocol (HTTP) 400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error so you should not use this logic .