Skip to content
Advertisement

AWS Lambda@Edge 502 LambdaValidationError in CloudFront for redirect

I have a lambda function which performs 301 redirect if it has uri that is generated using regex.

JavaScript

On deploying the function and adding it to the cloudfront behaviors, when I go to to the url https:my-website/xyz/faq/max, eventhough I see the status of 301 for https:my-website/xyz/faq/max after correctly re-routing to https:my-website/contact, it shows 502 Error. It shows the same error for https:my-website as well. In the chrome under status I see LambdaValidationError from cloudfront under Response Header. May I know what am I doing wrong here to throw this error? The pages are just static pages stored in AWS S3 bucket served using Amazon CloudFront.

Advertisement

Answer

Changing let finalUrl = ''; to let finalUrl = request.uri; helped me get rid of the error as I was setting it to empty string, the lambda was throwing 502 error as it wasn’t able re-direct the traffic when there is no uri in the request.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement