API HTTP网关路径重写问题

0

【以下的问题经过翻译处理】 你好, 我有一个与ALB后端相连的API HTTP网关,我正在尝试从API Gateway -> internet-faced ALB(使用HTTP URI integration)迁移到API Gateway -> VPC link -> internal ALB。 我的路由看起来像“/app1/{proxy+}”。在第一种情况下,我使用“https://app1.example.com/{proxy}}”,它将“api.example.com/v1/app1/user/add”重写为“https://app1.example.com/user/add”。 现在我想用VPC link integration做同样的重写,但我找不到方法。 使用“$request.path”重写路径给我“/app1/user/add”,使用“$request.path.proxy+”给我“/v1/app1/user/add”。

profile picture
EXPERT
asked 5 months ago22 views
1 Answer
0

【以下的回答经过翻译处理】 你好,

感谢联系我们并分享详细的用例情况。

覆盖路径的正确映射参数应为:

/$request.path.proxy

使用 "$request.path.proxy+" 会将路径设置为 "/v1/app1/user/add",因为该值是一个通配符路径变量。可以使用访问日志中的上下文变量 $context.path 进行验证。

正确的方式是使用 "$request.path.proxy" [1],这将在集成中为您提供路径值 "user/add",该值部分正确,因为在后端丢失了初始 "/",因此将抛出 4xx 错误。

因此,使用 "/$request.path.proxy+" 可以为您提供适合您用例的正确值 "/user/add"。如果在实施上述建议后仍有问题,请告诉我。

参考资料: [1] https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-http.html

profile picture
EXPERT
answered 5 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions