4

I have a CloudFront distribution with a Lambda@Edge function which handles viewer request event. I want to send some custom headers and have them processed by Lambda@Edge, however Lambda function doesn't see them. For example I tried to send following headers:

  • X-Abc-Me
  • X-Some-Strange-Header

In the event received by Lambda function above headers are not included in 'headers'. I've tried to look through CloudFront document but don't see any clue yet. Please help. Thanks a lot in advance.

Yaiba
  • 571
  • 7
  • 14
  • 5
    You need to include the header in cache policies or origin request policies — they tell CloudFront which headers you need available in Lamda@Edge or your origin. Use cache policies if the headers should be included in your cache key; otherwise use origin request policies. – Cristian Mar 14 '22 at 19:54
  • @Cristian thank you, after setting origin cache policies to forward headers to origin I can access custom headers in Lambda@Edge. Can you make this an answer so I can accept it? – Yaiba Mar 16 '22 at 00:20
  • Adding an header to the cache policy will also forward it by default. But there is another option, without adding it to the cache key and that is to use "Origin Request Policy" – omriman12 May 01 '22 at 10:43
  • I agree that this is missing from the documentation. I've requested additional information on this page (https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html) so PLEASE do the same. In the case that an origin request policy of "None" is used some standard headers will be received (e.g. "authorization") while others will be elided (e.g. "username"). Also, if the body is included some headers will be removed. In short: it's a mess! – AngelGabriel Nov 24 '22 at 22:03

0 Answers0