API 网关 HTTP 代理与无服务器离线集成(非 Lambda 代理)
API Gateway HTTP Proxy integration with serverless-offline (NOT Lambda Proxy)
我正在尝试使用无服务器离线在本地开发/模拟我的 API 网关。我的 API 网关自由使用了 HTTP proxy integrations。生产资源如下所示:
我根据一些文档和讨论创建了一个无服务器离线配置,这些文档和讨论表明可以使用 Cloud Formation 配置定义 HTTP 代理集成:
- httpProxyWithApiGateway.md - 使用无服务器框架在 API 网关上设置 HTTP 代理。
- Setting an HTTP Proxy on API Gateway(无服务器官方文档:API 网关)
我根据自己的需要改编了以上两个配置示例,请参见下文。
对于我在这里可能做错了什么,有什么提示吗?
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解决同样的问题,在下面post -
默认情况下 serverless-offline
不会为端点解析您的资源,通过自定义配置启用它。
custom:
serverless-offline:
resourceRoutes: true
结束服务:
Serverless: Routes defined in resources:
Serverless: ANY /endpoint/{proxy*} -> http://endpoint.company.cool/{proxy}
Serverless: Offline listening on http://localhost:3000
我正在尝试使用无服务器离线在本地开发/模拟我的 API 网关。我的 API 网关自由使用了 HTTP proxy integrations。生产资源如下所示:
我根据一些文档和讨论创建了一个无服务器离线配置,这些文档和讨论表明可以使用 Cloud Formation 配置定义 HTTP 代理集成:
- httpProxyWithApiGateway.md - 使用无服务器框架在 API 网关上设置 HTTP 代理。
- Setting an HTTP Proxy on API Gateway(无服务器官方文档:API 网关)
我根据自己的需要改编了以上两个配置示例,请参见下文。
对于我在这里可能做错了什么,有什么提示吗?
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解决同样的问题,在下面post -
默认情况下 serverless-offline
不会为端点解析您的资源,通过自定义配置启用它。
custom:
serverless-offline:
resourceRoutes: true
结束服务:
Serverless: Routes defined in resources:
Serverless: ANY /endpoint/{proxy*} -> http://endpoint.company.cool/{proxy}
Serverless: Offline listening on http://localhost:3000