[英]AWS API Gateway - Parameter mapping path with HTTP API (overwrite:path)
I started looking into using AWS HTTP API as a single point of entry to some micro services running with ECS.我开始研究使用 AWS HTTP API 作为使用 ECS 运行的一些微服务的单一入口。
One micro service has the following route internally on the server:一个微服务在服务器内部有如下路由:
/sessions/{session_id}/topics
I define exactly the same route in my HTTP API and use CloudMap and a VPC Link to reach my ECS cluster.我在我的 HTTP API 中定义了完全相同的路由,并使用 CloudMap 和 VPC 链接到达我的 ECS 集群。 So far so good, the requests can reach the servers.
到目前为止一切顺利,请求可以到达服务器。 The path is however not the same when it arrives.
然而,到达时路径并不相同。 As per AWS documentation [1] it will prepend the stage name so that the request looks the following when it arrives:
根据 AWS 文档 [1],它将在阶段名称前加上请求,以便请求在到达时看起来如下所示:
/{stage_name}/sessions/{session_id}/topics
So I started to look into Parameter mappings so that I can change the path for the integration, but I cannot get it to work.所以我开始研究参数映射,以便我可以更改集成路径,但我无法让它工作。
For requestParameters I want overwrite the path like below, but for some reason the original path with the stage variable is still there.对于 requestParameters,我想覆盖下面的路径,但由于某种原因,带有阶段变量的原始路径仍然存在。 If I just define overwrite:path as $request.path.sessionId I get only the ID as the path or if I write whatever string I want it will arrive as I define it.
如果我只是将 overwrite:path 定义为 $request.path.sessionId,我只会得到 ID 作为路径,或者如果我写任何我想要的字符串,它都会按照我的定义到达。 But when I mix the $request.path.sessionId and the other parts of the string it does not seem to work.
但是当我混合 $request.path.sessionId 和字符串的其他部分时,它似乎不起作用。
How do I format this correctly?如何正确格式化?
paths:
/sessions/{sessionId}/topics:
post:
responses:
default:
description: "Default response for POST /sessions/{sessionId}/topics"
x-amazon-apigateway-integration:
requestParameters:
overwrite:path: "/sessions/$request.path.sessionId/topics"
payloadFormatVersion: "1.0"
connectionId: (removed)
type: "http_proxy"
httpMethod: "POST"
uri: (removed)
connectionType: "VPC_LINK"
timeoutInMillis: 30000
[1] https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-private.html [1] https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-private.html
You can try to use parentheses.您可以尝试使用括号。 Formal notation instead of shorthand notation.
形式符号代替速记符号。
overwrite:path: "/sessions/${request.path.sessionId}/topics"覆盖:路径:“/sessions/${request.path.sessionId}/topics”
It worked well for me for complex mappings.它对我来说适用于复杂的映射。
mapping template is a script expressed in Velocity Template Language (VTL)映射模板是用速度模板语言 (VTL) 表示的脚本
dont remove the uri and the connectionId and it will work for you.不要删除 uri 和 connectionId,它会为你工作。 add only requestParameters: overwrite:path: "/sessions/$request.path.sessionId/topics"
仅添加 requestParameters: overwrite:path: "/sessions/$request.path.sessionId/topics"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.