问题
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:
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)
回答1:
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+}'
来源:https://stackoverflow.com/questions/55129135/api-gateway-http-proxy-integration-with-aws-sam-not-lambda-proxy