[英]Serverless: Deploy to same api from different yml
我有api api.demo
具有以下结构
api.demo
/service1:
GET /test1
GET /test2
...
/service2
GET /test1
GET /test2
...
我有两个单独的文件夹service1, service2
每个文件夹service1, service2
自己的service1, service2
文件。部署时,它将在api网关中创建两个单独的api,如下所示
api.demo(id1)
/service1:
GET /test1
GET /test2
...
api.demo(id2)
/service2
GET /test1
GET /test2
如何更新service2以采用相同的api端点api.demo(id1)?
我该如何实现? 任何指针都会有所帮助。
只需使用自定义域名即可: http : //docs.aws.amazon.com/apigateway/latest/developerguide/how-to-custom-domains.html
您可以将基本路径映射到API,因此可以将/service1
映射到第一个API,将/service2
到第二个API。 客户将使用自定义域名,而不是我们提供的默认execute-api
端点。
在主要服务中:
resources:
Outputs:
ApiGatewayRestApiId:
Value:
Ref: ApiGatewayRestApi
Export:
Name: prod-ApiGatewayRestApiId
ApiGatewayRestApiRootResourceId:
Value:
Fn::GetAtt:
- ApiGatewayRestApi
- RootResourceId
Export:
Name: prod-ApiGatewayRestApiRootResourceId
在二级服务中:
provider:
name: aws
runtime: nodejs8.10
stage: dev
region: us-east-1
apiGateway:
restApiId:
'Fn::ImportValue': prod-ApiGatewayRestApiId
restApiRootResourceId:
'Fn::ImportValue': prod-ApiGatewayRestApiRootResourceId
来源: https : //serverless-stack.com/chapters/api-gateway-domains-across-services.html
https://serverless.com/framework/docs/providers/aws/guide/services/
注意:当前,每个服务都会在AWS API Gateway上创建一个单独的REST API。 由于AWS API Gateway的限制,每个一个REST API只能有一个自定义域。 如果您打算制作大型REST API,请注意此限制。 此外,修复工作正在进行中,并且是当务之急。
可以在此处跟踪正在进行的修复。
相关论坛主题有一些建议。 可能最简单的方法是拥有一个额外的API网关,该网关可以通过以下方式委派给真实的网关
但是,这些选择都不是没有缺陷的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.