我正在配置 lambda 函数的 API 网关与 Serverless Framework 的集成版本 0.4.2。
我的问题是定义端点的请求参数。 AWS docs for API gateway条目说:
requestParameters
Represents request parameters that can be accepted by Amazon API Gateway. Request parameters are represented as a key/value map, with a source as the key and a Boolean flag as the value. The Boolean flag is used to specify whether the parameter is required. A source must match the pattern method.request.{location}.{name}, where location is either querystring, path, or header. name is a valid, unique parameter name. Sources specified here are available to the integration for mapping to integration request parameters or templates.
据我了解,
s-function.json
中的配置直接提供给 AWS CLI,因此我以以下格式指定了请求参数:"method.request.querystring.startYear": true
.但是,我收到了 Invalid mapping expression specified: true
错误。我也试过将配置指定为 "method.request.querystring.startYear": "true"
结果相同。s-function.json
:{
"name": "myname",
// etc...
"endpoints": [
{
"path": "mypath",
"method": "GET",
"type": "AWS",
"authorizationType": "none",
"apiKeyRequired": false,
"requestParameters": {
"method.request.querystring.startYear": true,
"method.request.querystring.startMonth": true,
"method.request.querystring.startDay": true,
"method.request.querystring.currentYear": true,
"method.request.querystring.currentMonth": true,
"method.request.querystring.currentDay": true,
"method.request.querystring.totalDays": true,
"method.request.querystring.volume": true,
"method.request.querystring.userId": true
},
// etc...
}
],
"events": []
}
有任何想法吗?提前致谢!
最佳答案
它看起来像 requestParameters
在 s-function.json
文件适用于 configuring the integration request section ,所以我最终使用了:
"requestParameters": {
"integration.request.querystring.startYear" : "method.request.querystring.startYear",
"integration.request.querystring.startMonth" : "method.request.querystring.startMonth",
"integration.request.querystring.startDay" : "method.request.querystring.startDay",
"integration.request.querystring.currentYear" : "method.request.querystring.currentYear",
"integration.request.querystring.currentMonth" : "method.request.querystring.currentMonth",
"integration.request.querystring.currentDay" : "method.request.querystring.currentDay",
"integration.request.querystring.totalDays" : "method.request.querystring.totalDays",
"integration.request.querystring.volume" : "method.request.querystring.volume",
"integration.request.querystring.userId" : "method.request.querystring.userId"
},
这最终将它们自动添加到 方法请求 仪表板上的部分也是:
然后我可以在映射模板中使用它们将它们转换为方法帖子,该帖子将作为
event
发送。进入我的 Lambda 函数。现在我有一个我正在使用的特定映射模板,但我将来可能会使用 Alua K's suggested method以通用方式映射所有输入,这样我就不必为每个函数配置单独的映射模板。
关于amazon-web-services - requestParameters 返回 "Invalid mapping expression specified: true",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36122250/