Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API Gateway HTTP Proxy integration with aws-sam (NOT Lambda Proxy)

I am trying to use aws-sam 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

All of the aws-sam examples which I've found, as well as related documentation and Q&A, use the Lambda integrations / have a hard dependency on a Lambda function being the proxied resource, versus an HTTP Proxy integration.

Is there a way to define an HTTP Proxy resource for an aws-sam application? (As opposed to a Lambda Proxy resource?)

Related:

  • Create an API Gateway Proxy Resource using SAM
  • I am also attempting to solve the same problem using serverless-offline, at the following post - API Gateway HTTP Proxy integration with serverless-offline (as opposed to a Lambda Proxy)
like image 837
Daniel B. Avatar asked Mar 12 '19 19:03

Daniel B.


People also ask

How you should and should not use API gateway proxy integration with Lambda?

However, if your Lambda is only ever invoked by API Gateway, use the proxy integration with these guidelines: Avoid greedy path variables, except perhaps for a catch-all 404. Avoid using the ANY method. Define request models and enable request validation (remember it's off by default).

What is the difference between AWS Gateway API and Lambda?

AWS API Gateway is a fully managed service that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale. Lambda is function as a service(FAAS) product of AWS. The combination of these two services is amazing and it is slowly replacing the traditional backend.

Does API gateway need Lambda?

API calls are made from various external apps; they are processed by API Gateway, and are routed to Lambda for processing. Lambda may use other AWS services to complete a request, and, once complete, it sends back the response to the external app via API gateway.


1 Answers

Yes, SAM is just a Cloud Formation transform. So you can still create traditional CloudFormation objects as usual. You might be able to also attach it to your Serverless::API but I am less confident about that.

Resource:
  Api:
    Type: 'AWS::ApiGateway::RestApi'
    Properties:
      Description: A test API
      Name: MyRestAPI

    Type: 'AWS::ApiGateway::Resource'
    Properties:
      ParentId: !GetAtt Api.RootResourceId
      RestApiId: !Ref Api
      PathPart: '{proxy+}'

or possibly (untested):

Resource:
  Api:
    Type: 'AWS::Serverless::Api'
    Properties:
      Description: A test API
      Name: MyRestAPI

    Type: 'AWS::ApiGateway::Resource'
    Properties:
      ParentId: !GetAtt Api.RootResourceId
      RestApiId: !Ref Api
      PathPart: '{proxy+}'
like image 75
J.A. Simmons V Avatar answered Oct 20 '22 12:10

J.A. Simmons V