Search code examples
amazon-web-servicesaws-lambdaaws-api-gateway

How to access HTTP headers for request to AWS API Gateway using Lambda?


I see in the API Gateway FAQ that it is possible to access the request headers sent to the API Gateway...

If you already utilize OAuth tokens or any other authorization mechanism, you can easily setup API Gateway not to require signed API calls and simply forward the token headers to your backend for verification.

However, I can find no example of how to do so in the documentation and it is unclear how to access this data using Lambda.

I am able to set up an open API and gain access to the JSON object that is part of a POST (Walkthrough: API Gateway and Lambda Functions), but in order to implement a OAuth 2.0 style API with my own provider I need access to the "Authorization" header.

My preference is to set this up using Lambda and Java 8, but an example using node.js would also be helpful in understanding how to accomplish this.


Solution

  • You need to create input mapping inside Integration Request panel on the dashboard screen describing your API method.

    Following code translates name query input parameter into Lambda Event input object:

    {
       "name": "$input.params('name')"
    }
    

    Screenshot:

    API Dashboard screenshot

    You can find more info about this in the original API Gateway to Lambda input thread on AWS Forums.