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

前端 未结 7 1995
终归单人心
终归单人心 2020-11-28 23:38

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 o

7条回答
  •  失恋的感觉
    2020-11-29 00:26

    First, you need to trap the Authorization header from the HTTP GET request. Then you need to map that value to the Lambda event object.

    Go to the API method dashboard and click on Method Request. In there you can add an HTTP Request Header called Authorization as shown below.

    HTTP Request Headers

    This will trap the Authorization header so you can use it later.

    Now go back to the method dashboard and click on Integration Request. From here you can pass the value of the header into the Lambda function by using a mapping like this.

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

    Now in your Lambda function you can get the value like this.

    event.Authorization
    

提交回复
热议问题