API 网关 HTTP 代理与无服务器离线集成(不是 Lambda 代理)

Dan*_* B. 5 aws-api-gateway serverless-framework serverless serverless-offline

我正在尝试使用无服务器离线在本地开发/模拟我的 API 网关。我的 API 网关自由地使用了HTTP 代理集成。生产资源如下所示:

API 网关资源方法上的 HTTP 代理集成的屏幕截图

我根据一些文档和讨论创建了一个无服务器离线配置,这些文档和讨论表明可以使用 Cloud Formation 配置定义 HTTP 代理集成:

我已根据我的目的改编了上述两个配置示例,请参见下文。

有什么提示,我可能在这里做错了什么?

plugins:
  - serverless-offline

service: company-apig
provider:
  name: aws
  stage: dev
  runtime: python2.7

resources:
  Resources:

    # Parent APIG RestApi
    ApiGatewayRestApi:
      Type: AWS::ApiGateway::RestApi
      Properties:
        Name: company-apig
        Description: 'The main entry point of the APIG'

    # Resource /endpoint
    EndpointResource:
      Type: AWS::ApiGateway::Resource
      Properties:
        ParentId:
          Fn::GetAtt:
            - ApiGatewayRestApi
            - RootResourceId
        PathPart: 'endpoint'
        RestApiId:
          Ref: ApiGatewayRestApi

    # Resource /endpoint/{proxy+}
    EndpointProxyPath:
      Type: AWS::ApiGateway::Resource
      Properties:
        ParentId:
          Ref: EndpointResource
        PathPart: '{proxy+}'
        RestApiId:
          Ref: ApiGatewayRestApi

    # Method ANY /endpoint/{proxy+}
    EndpointProxyAnyMethod:
      Type: AWS::ApiGateway::Method
      Properties:
        AuthorizationType: NONE
        HttpMethod: ANY
        Integration:
          IntegrationHttpMethod: ANY
          Type: HTTP_PROXY
          Uri: http://endpoint.company.cool/{proxy}
          PassthroughBehavior: WHEN_NO_MATCH
        MethodResponses:
          - StatusCode: 200
        ResourceId:
          Ref: EndpointProxyPath
        RestApiId:
          Ref: ApiGatewayRestApi
Run Code Online (Sandbox Code Playgroud)

对于上述配置,我得到了这个输出。显然,配置根本没有注册路由。

{
  "statusCode":404,
  "error":"Serverless-offline: route not found.",
  "currentRoute":"get - /endpoint/ping",
  "existingRoutes":[]
}
Run Code Online (Sandbox Code Playgroud)

相关:我也在尝试使用 aws-sam 解决同样的问题,在以下帖子中 - API Gateway HTTP Proxy integration with aws-sam (NOT Lambda Proxy)

Ale*_*lex 3

默认情况下serverless-offline不会解析端点的资源,请通过自定义配置启用它。

custom:
  serverless-offline:
    resourceRoutes: true
Run Code Online (Sandbox Code Playgroud)

最终服务:

Serverless: Routes defined in resources:
Serverless: ANY /endpoint/{proxy*} -> http://endpoint.company.cool/{proxy}

Serverless: Offline listening on http://localhost:3000
Run Code Online (Sandbox Code Playgroud)

文档