使用serverless-offline进行API网关HTTP代理集成(非Lambda代理)

5
我正在尝试使用serverless-offline在本地开发/模拟我的API Gateway。我的API网关大量使用HTTP代理集成。生产资源如下所示:

Screenshot of an HTTP Proxy integration on an API Gateway Resource Method

我已经根据一些文件和讨论创建了一个基于无服务器架构的离线配置,这些文件和讨论表明可以使用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

根据以上配置,我得到了这个输出。显然,此配置未注册任何路由。
{
  "statusCode":404,
  "error":"Serverless-offline: route not found.",
  "currentRoute":"get - /endpoint/ping",
  "existingRoutes":[]
}

相关: 我也正在尝试使用aws-sam解决相同的问题,在以下帖子中 - API Gateway HTTP代理集成与aws-sam(非Lambda代理)

1个回答

3
默认情况下,serverless-offline不会解析你的资源以获取端点,可以通过自定义配置启用。最初的回答是:按照自定义配置启用serverless-offline来解析资源以获取端点。
custom:
  serverless-offline:
    resourceRoutes: true

最终提供的是:

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

Serverless: Offline listening on http://localhost:3000

Documentation


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接