Skip to content

How do I troubleshoot 502 and 503 errors that Lambda@Edge functions cause in CloudFront?

2 minute read
0

I want to troubleshoot the 502 and 503 errors I receive when I associate an AWS Lambda@Edge function with an Amazon CloudFront distribution.

Resolution

The Lambda@Edge function returns a 502 error

The "502" error occurs when the Lambda@Edge function returns an incorrectly formed response, or the Lambda@Edge function includes content that isn't valid. The object structure of the response must match the Lambda@Edge event structure.

To resolve the "502" error, take the following actions:

  • Verify that the Lambda@Edge function returns a valid JSON object.
  • Make sure that the response includes all the required fields based on the event type.
  • Verify that objects in the response are valid and follow the expected structure.
  • Check whether your edge function added a disallowed HTTP header.
  • Remove read-only headers.
  • Make sure that the Lambda@Edge function doesn't exceed the request body size of 1 MB for origin request events or 40 KB for viewer request events.
  • Check for characters or values in the response fields that aren't valid.

For more information, see Test and debug Lambda@Edge functions and Restrictions on Lambda@Edge.

The Lambda@Edge function returns a 503 error

The "503" error occurs when there are unhandled exceptions or errors in the function code.

To resolve this issue, add logging statements, for example console.log()), in your Lambda@Edge function to write to Amazon CloudWatch Logs. Review the CloudWatch logs in the AWS Region where CloudFront runs the function.

For more information, see Four steps for debugging your content delivery on AWS and Troubleshoot execution issues in Lambda.

Lambda blocks the function execution when you exceed Lambda@Edge quota. Check the Lambda@Edge CloudWatch metrics for issues, such as exceeded concurrent executions in each AWS Region and exceeded functions.

AWS OFFICIALUpdated 2 months ago