API Gateway HTTP Proxy integration with serverless-offline (NOT Lambda Proxy)
Asked Answered
G

1

5

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:

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

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:

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":[]
}

Related: I am also attempting to solve the same problem using aws-sam, at the following post - API Gateway HTTP Proxy integration with aws-sam (NOT Lambda Proxy)

Ghyll answered 12/3, 2019 at 19:50 Comment(0)
G
3

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

custom:
  serverless-offline:
    resourceRoutes: true

Ends up serving:

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

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

Documentation

Gama answered 13/3, 2019 at 3:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.