无法读取AWS中的查询参数
问题描述:
我想将查询参数从API网关传递到AWS Lambda,但我总是收到null
值。无法读取AWS中的查询参数
这是我的Lambda函数,我只想返回http://foo.bar的值? 名=丹
'use strict';
exports.handle = (context, event, callback) => {
callback(null, event.name);
}
在API网关我也做了以下内容:
- 创建资源
- 创建方法(
GET
) - 选择了正确的lambda函数
- 选择我的GET方法并点击
Integration Request
- 选择
Body Mapping Templates
- 集的Content-Type到
application/json
- 新增
{"name": "$input.params('name')" }
- 保存和部署!
但是,当我加载我的API时,event.name
的值总是null
。访问API通过...amazonaws.com/beta/user?name=dan
编辑完成的:我已经试过接受的答案here但毕竟只是在回调返回时,我只收到此数据:
{
"callbackWaitsForEmptyEventLoop": true,
"logGroupName": "",
"logStreamName": "",
"functionName": "",
"memoryLimitInMB": "",
"functionVersion": "",
"invokeid": "",
"awsRequestId": "",
"invokedFunctionArn": ""
}
我省略了值。
答
函数参数为context
和event
位置是错误的。更改它们的位置如下
'use strict';
exports.handle = (event, context, callback) => {
callback(null, event.name);
}
答
即使我之前有同样的问题,我已经修改了身体映射模板,如下所示。请尝试一下。
#set($inputRoot = $input.path('$'))
{
"name" : "$input.params('$.name')"
}
如果您使用路径参数,那么请尝试以下,
#set($inputRoot = $input.path('$'))
{
"name" : "$input.path('$.name')"
}
呃,这样一个愚蠢的错误!非常感谢你。 – Dan
不客气。 –
好点的伴侣:)。想给10 upvote,但它只允许一个:) –