API网关HTTP代理与无服务器脱机(非Lambda代理)集成

问题描述 投票:2回答:1

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

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 Proxy integration with aws-sam (NOT Lambda Proxy)

aws-api-gateway serverless-framework serverless serverless-offline
1个回答
1
投票

默认情况下,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

© www.soinside.com 2019 - 2024. All rights reserved.