1
votes

We're planning to use API Gateway as REST API HTTP proxy only initially - as we have existing REST service and we wish to split it into smaller parts under covers without changing client interface (possibly later replacing some of those parts with lambda functions).

Before we do that, I wish to see if we will have any support running such scenario locally, hence I've configured API gateway in AWS management console and exported OpenAPI definition.

So my template.yaml looks like

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: Demo SAM API
Resources:
  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: test
      DefinitionBody:
        'Fn::Transform':
          Name: AWS::Include
          Parameters:
            Location: swagger.yaml

and swagger.yaml looks following:

openapi: "3.0.1"
info:
  title: "Test.API"
  description: "Test.API"
  version: "2020-09-14T07:49:45Z"
servers:
- url: "https://dummydomain.com"
paths:
  /api/v3/Client:
    get:
      x-amazon-apigateway-integration:
        type: "http_proxy"
        uri: "https://dummydommain.com/api/v3/client"
        passthroughBehavior: "when_no_match"
        httpMethod: "GET"
        timeoutInMillis: 29000
components: {}

And running sam local start-api --debug this gives error:

Error: Template does not have any APIs connected to Lambda functions

I've added dummy lambda function just to pass through the error, but still no luck - it had message in debug output:

Lambda function integration not found in Swagger document at path='/api/v3/client' method='get'

and responded to `http://localhost:3000/api/v3/client' with:

{"message":"Missing Authentication Token"}

Does this mean, that SAM is very very coupled to lambda's and it won't run API gateway as proxy locally or I'm doing something stupid?

1
...does not have any APIs connected to Lambda functions Where's your lambda function?petey
@petey - that's the point, I need only apigateway doing http proxying, I don't need any lambda at the moment.Giedrius
yea, you should hook up a lambda function. I dont think it will work without it.petey
@Giedrius, I have the same scenario. How did you solve this?Marcell Alves
@MarcellAlves - I've dropped the idea to use SAM for my purposes - too much trouble, I've faced other issues as well without clear answers.Giedrius

1 Answers

0
votes

Add Lambda integration to your template.yaml file:

YourLambdaFunction:
        Type: AWS::Serverless::Function 
        Properties:
            CodeUri: path/to/your/lambda/
            Role: arn:aws:iam::<ACCOUNT_NUMBER>:role/service-role/role-for-lambda
            Events:
                YourGetEvent:
                    Type: Api 
                    Properties:
                        Path: /api/v3/Client
                        Method: get
                        RestApiId:
                            Ref: MyApi