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

Fly*_*n81 6 amazon-web-services aws-api-gateway

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

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

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

Kau*_*kar 4

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

如果您使用 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"
Run Code Online (Sandbox Code Playgroud)

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