如何使用lambda访问HTTP标头请求AWS API网关?网关、如何使用、lambda、HTTP

2023-09-11 10:29:10 作者:回忆很美却很伤

我的 API网关常见问题解答,它可以访问发送到API请求头中看到的网关...

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

如果您已经使用OAuth的令牌或任何其它授权   机制,你可以很容易地安装API网关不要求签名的API   电话和简单地把令牌头到你的后端   验证。

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.

不过,我可以找到如何做到这一点的文档中没有例子,目前还不清楚如何使用lambda来访问这些数据。

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.

我能够建立一个开放的API,并获得了JSON对象,它是一个POST的一部分(Walkthrough: API网关和Lambda功能的),但为了实现OAuth的2.0风格的API与我自己的供应商,我需要获得授权头。

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.

我的preference是使用lambda和Java 8对此进行设置,但使用Node.js的一个例子也将有助于理解如何做到这一点。

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.

推荐答案

您需要创建仪表盘屏幕上的集成请求面板内输入映射描述你的API方法。

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

随着code转换名称查询输入参数为 LAMBDA事件输入对象

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

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

截图:

您可以找到有关这个原来 API网关LAMBDA输入线程的详细信息在AWS论坛的。

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