'Reading Custom Headers on Lambda Edge request

I am using a Lambda Edge triggered by viewer-request to control access to a Cloudfront Distribution Origin (S3 Bucket). I want to allow/deny access to the distribution by sending an IdToken and a UID (user ID) string. My code basically decodes the IdToken and reads a decodedUID inside it, then compares it to the UID passed as a header and if they match or not it allows/deny access to the Origin

I am using SAM to deploy all of this, when I test this code locally it works as it should but when I deploy the changes to AWS one of the two headers is not being received by the lambda

I am sending two headers with each request to the Cloudfront Distribution

  • Authorization
  • UID

But the UID Header is never reaching the lambda edge in the event

I am using Nodejs14.x as runtime, when I run console.log(request.headers) I see the Authorization header with the token but not the UID

Does someone know why is this happening and how can I fix it?

I managed to send the UID value as a query parameter but that solution is not fitting to what I need



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source