API网关HTTP代理与无服务器离线的集成(非Lambda代理) [英] API Gateway HTTP Proxy integration with serverless-offline (NOT Lambda Proxy)

查看:145
本文介绍了API网关HTTP代理与无服务器离线的集成(非Lambda代理)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用无服务器离线在本地开发/模拟我的API网关.我的API网关自由使用

I am trying to use serverless-offline to develop / simulate my API Gateway locally. My API gateway makes liberal use of the HTTP proxy integrations. The production Resource looks like this:

我已经基于一些文档和讨论创建了无服务器脱机配置,其中说有可能使用Cloud Formation配置来定义HTTP代理集成:

I have created a serverless-offline configuration based on a few documents and discussion which say that it is possible to define an HTTP Proxy integration using Cloud Formation configuration:

  • httpProxyWithApiGateway.md - Setting an HTTP Proxy on API Gateway by using Serverless framework.
  • Setting an HTTP Proxy on API Gateway (official Serverless docs: API Gateway)

出于我的目的,我已经修改了上面的两个配置示例,请参见下文.

I have adapted the above two configuration examples for my purposes, see below.

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

Have any tips, for what I might be doing wrong here?

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

对于以上配置,我得到此输出.显然,该配置根本没有注册任何路由.

For the above configuration, I get this output. Apparently, the configuration registers no routes at all.

{
  "statusCode":404,
  "error":"Serverless-offline: route not found.",
  "currentRoute":"get - /endpoint/ping",
  "existingRoutes":[]
}

相关:在以下帖子中,我还尝试使用aws-sam解决相同的问题-推荐答案

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

By default serverless-offline doesn't parse your resources for endpoints, enable it via custom config.

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

文档

这篇关于API网关HTTP代理与无服务器离线的集成(非Lambda代理)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆