【问题标题】:Path parameters ignored by AWS API Gateway using proxy+AWS API Gateway 使用 proxy+ 忽略的路径参数
【发布时间】:2022-06-30 01:01:27
【问题描述】:

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

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

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

【问题讨论】:

    标签: amazon-web-services aws-api-gateway


    【解决方案1】:

    在您的集成中,端点 URL 应为 http://loadbalancerurl/{proxy}。我找不到任何专门针对 VPC 链接集成的文档,但有一个针对 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"
    

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

    【讨论】:

      【解决方案2】:

      对我有用的是添加以下属性:

      Resources:
        APIGWProxyMethod:
          Type: AWS::ApiGateway::Method
          Properties:
            RequestParameters: 
              method.request.path.proxy: true # enable proxy
            Integration:
              RequestParameters:
                integration.request.path.proxy: method.request.path.proxy # map method proxy param to integration proxy param
            ... # the rest of integration property
          ... # other properties
      

      有帮助的文章:

      【讨论】:

        猜你喜欢
        • 2018-07-30
        • 2018-02-25
        • 1970-01-01
        • 2016-02-06
        • 1970-01-01
        • 2017-08-29
        • 1970-01-01
        • 1970-01-01
        • 2019-10-28
        相关资源
        最近更新 更多