amazon-web-services - requestParameters 返回 "Invalid mapping expression specified: true"

标签 amazon-web-services aws-cli aws-api-gateway serverless-framework

我正在配置 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": []
}
有任何想法吗?提前致谢!

最佳答案

它看起来像 requestParameterss-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"
},

这最终将它们自动添加到 方法请求 仪表板上的部分也是:

Method request section with parameters automatically added

然后我可以在映射模板中使用它们将它们转换为方法帖子,该帖子将作为 event 发送。进入我的 Lambda 函数。现在我有一个我正在使用的特定映射模板,但我将来可能会使用 Alua K's suggested method以通用方式映射所有输入,这样我就不必为每个函数配置单独的映射模板。

关于amazon-web-services - requestParameters 返回 "Invalid mapping expression specified: true",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36122250/

相关文章:

node.js - AWS Lambda 复制对象 "Process exited before completing request"

aws-lambda - AWS CLI - 如何为 cognito 用户生成安全 token

amazon-web-services - 查明 FCM 推送通知状态 "Successful"但未在控制台/设备中收到

amazon-web-services - SQS消息接收乱序

openshift - 我可以在 oc exec 命令中使用通配符吗?

windows - aws cli 没有输出

javascript - 将节点请求模块与 AWS Lambda 和 API Gateway 结合使用

amazon-web-services - 用于 Lambda 的 AWS 状态机,cloudformation 语法

amazon-web-services - .NET Core API Gateway (AWS) 如何设置依赖注入(inject) (DI) 以使用 MemCached .NET Core 包、基于 DI 的记录器等

php - 即使已在 AWS SQS PHP SDK 中提供,也会出现缺少参数错误