我正在尝试使用serverless-offline在本地开发/模拟我的API Gateway。我的API网关大量使用HTTP代理集成。生产资源如下所示:
我已经根据一些文件和讨论创建了一个基于无服务器架构的离线配置,这些文件和讨论表明可以使用Cloud Formation配置来定义HTTP代理集成:
根据以上配置,我得到了这个输出。显然,此配置未注册任何路由。
- httpProxyWithApiGateway.md - 使用Serverless框架在API Gateway上设置HTTP代理。
- 在API Gateway上设置HTTP代理(官方Serverless文档:API Gateway)
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
根据以上配置,我得到了这个输出。显然,此配置未注册任何路由。
{
"statusCode":404,
"error":"Serverless-offline: route not found.",
"currentRoute":"get - /endpoint/ping",
"existingRoutes":[]
}
相关: 我也正在尝试使用aws-sam解决相同的问题,在以下帖子中 - API Gateway HTTP代理集成与aws-sam(非Lambda代理)