如何访问AWS API网关的路径参数?

How to access the path parameter of AWS API Gateway?

我在 API 网关中创建了一个基本的 GET url;带有一个名为 "name".

的路径参数

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

我是不是弄错了参数路径的用途?

让我以我的游戏应用为例:

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 网关实现吗?

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

修改他们的示例("Example Request and Response" 靠近底部)以适合您的 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"
    }
}