AWS API Gateway using proxy+ 忽略的路径参数

Path parameters ignored by AWS API Gateway using proxy+

我在 AWS API 网关上有一个 REST API。它有一个资源 /{proxy+},它是用 ANY 方法配置的。集成请求设置为 VPC_PROXY,这意味着它使用 VPC Link。 VPC link 是一个网络负载均衡器,该负载均衡器正在使用 Fargate 在 ECS 集群上 运行 前面的应用程序。

当使用控制台的选项测试 API 时,我可以确认请求正在到达我的应用程序,但根据我的日志记录,请求的资源始终是 /。如果我尝试在控制台的方法测试屏幕中设置 {proxy} 值,我的应用程序似乎只会收到 / 的请求。如果我将 {proxy} 设置为类似 widget/5 的内容,我收到的响应就好像我在请求 /.

我想知道是否有某种方法可以解决这个问题,搜索 AWS 文档我无法弄清楚我的设置哪里出了问题。

在您的集成中,端点 URL 应该是 http://loadbalancerurl/{proxy}。我找不到任何专门针对 VPC Link 集成的文档,但是 HTTP proxy integration 有一个教程,其中包含类似的步骤。

如果您使用的是 openapi 规范,集成部分将如下所示:

x-amazon-apigateway-integration:
  uri: "http://loadbalancerurl/{proxy}"
  responses:
    default:
      statusCode: "200"
  requestParameters:
    integration.request.path.proxy: "method.request.path.proxy"
  passthroughBehavior: "when_no_match"
  connectionType: "VPC_LINK"
  connectionId: "your-vpclink-id"
  httpMethod: "ANY"
  type: "http_proxy"

使用控制台时,当我将 {proxy} 添加到端点 URL 时,integration.request.path.proxy: "method.request.path.proxy" 映射会自动添加。