重写 api 网关集成请求中的目标路径

Rewrite destination path in api gateway integration request

假设我在 API 网关中有这样的资源:/foo/{bar}。我想通过集成请求模板将请求路径转换为 ​​/bing/baz/{bar}。

通过以下方式直接将 'bar' 设置到请求正文中:

{ "bar": "$inputs.params('bar')" }

如何在请求时重写目标路径?

'Example Request Response' 中暗示了解决方案:

https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html

但文档并未准确概述 'With input template:' 的功能。

Resource: /things/{id}

With input template:
{
    "id" : "$input.params('id')",
    "count" : "$input.path(‘$.things').size()",
    "things" : $input.json(‘$.things')
}

您可能正在寻找映射模板变量“$context.resourcePath”,它将为您提供发出请求的资源路径。

编辑:

您可以在 HTTP 集成的 URI 字段中使用路径参数,这允许您动态地将正文中的参数或字段映射到目标路径。语法与资源相同,因此参数周围有大括号,如“http://myapi.com/foo/bar/{baz}”。

然后您就可以为 'baz' 指定一个映射表达式。