node.js - 如何访问AWS API Gateway的路径参数?

标签 node.js aws-lambda aws-api-gateway

我在 API Gateway 中创建了一个基本的 GET url;带有名为“name”的路径参数。

如何访问此名称参数?我在任何事件或上下文中都没有看到它。

我是否误解了参数路径的目的?

让我使用我的 Play 应用程序为例:

GET /api/v1/person                      @controllers.PersonController.list(limit: Int ?= 50, offset: Long ?= 0)
GET /api/v1/person/$id<[0-9]+>          @controllers.PersonController.getById(id: Long)
GET /api/v1/person/$id<[0-9]+>/email    @controllers.PersonController.getEmailByPersonId(id: Long)

这可以使用 AWS API Gateway 实现吗?

最佳答案

根据文档,您应该能够使用映射模板来执行此操作:http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html

修改他们的示例(底部附近的“示例请求和响应”)以适合您的 URI,它看起来像这样

//Resource: /api/v1/person/{id}

//With input template(this is what your lambda will see in the event):
{
    "id" : "$input.params('id')"
    "person" : $input.json(‘$.person')
}

//POST /api/v1/person/{id}
{
    "person" : {
        "name": "bob"
    }
}

关于node.js - 如何访问AWS API Gateway的路径参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33555279/

相关文章:

amazon-web-services - AWS API Gateway 中的单点登录

javascript - nodeJS "Cannot find module"中的 uglify-js

javascript - Jade 包括检查实际页面的条件

javascript - 在 lambda 中使用 node.js 如何解析来自 kinesis 流的数据

amazon-web-services - 如何使 AWS API 网关指向 "understand"尾部斜杠?

amazon-web-services - 将响应从 Lambda 返回给 API Gateway

javascript - 安全地存储 Web 推送通知的订阅 JS/Node.js

node.js - 从 firebase 函数 node.js 服务器的 tmp 目录上传合成语音

javascript - Alexa 内置插槽类型 : No value being passed

unity3d - 在 Unity3D C# 中签署 AWS Api 网关请求