aws-lambdaamazon-cloudfrontserverlessaws-api-gatewaycustom-headers

How to I pass my customer header from Postman to CloudFront distribution to API Gateway?


I have a API Gateway sitting behind CloudFront. I have a custom header called 'header1'. I want to pass its value from Postman to CloudFront to API Gateway. I have a lambda sitting behind the API Gateway and I want to use the 'header1' value inside the lambda. I created a custom header inside the origins of the distribution, but it never picks the value from Postman. It always passes the value I set up inside the CloudFront. Any help would be appreciated!


Solution

  • To proxy a custom request header to your origin, you need to tell CloudFront to include that header in the request CloudFront makes to your origin. You can do this using policies by either:

    1. Using a cache policy. Under headers > Include the following headers, add your custom header there
    2. Using an origin request policy. Also under headers, choose the option that makes sense for your application and add the custom header there.

    If the header should be included in your cache key, use a cache policy. Otherwise use an origin request policy.

    Additional details here: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/working-with-policies.html