我在使用CloudFormation使用Serverless框架在AWS中部署应用程序时遇到了问题。
我正在使用“单一API网关项目”策略进行部署。我将我的后端划分为服务,每个服务都有自己的目录在回购和serverless.yml文件中。
为了为其中每一个创建一个API,我首先部署一个根服务,它为我创建上述API,输出-- ApiGatewayRestApiId和ApiGatewayRestApiRootResourceId --正如我在同一服务器无服务器框架的以下文档中所看到的:
创建API网关的根服务如下所示:
...
resources:
Outputs:
ApiGatewayRestApiId:
Value:
Ref: ApiGatewayRestApi
Export:
Name: ${self:provider.stage}-ApiGatewayRestApiId
ApiGatewayRestApiRootResourceId:
Value:
Fn::GetAtt:
- ApiGatewayRestApi
- RootResourceId
Export:
Name: ${self:provider.stage}-ApiGatewayRestApiRootResourceId
...然后,从其他微服务中导入这些值,如下所示:
service: name
custom:
APP_ENV: ${env:SERVERLESS_APP}
providers:
apiGateway:
restApiId: !ImportValue ${env:${self:custom.APP_ENV}_API_STAGE}-ApiGatewayRestApiId
restApiRootResourceId: !ImportValue ${env:${self:custom.APP_ENV}_API_STAGE}-ApiGatewayRestApiRootResourceId
...直到今天我尝试只部署根服务时,我才遇到任何部署问题。我遇到的错误如下:
An error occurred: root-beta - Template error: RootResourceId attribute of API Gateway RestAPI d8zc1j912b doesn't exist.
我到处都查过了,但是我找不到为什么我会犯这个错误。
13.10.0
发布于 2022-10-06 01:54:56
根据我刚才在Github上看到的一条评论,这是由一个由200多个资源组成的API造成的。CloudFormation (用于部署无服务器资源)仅检索多达8页的25种资源来定位根资源id,因此如果它恰好位于页9+上,则会抛出该错误。
我不太清楚这些资源的顺序是什么。在我自己的测试中,有时起作用,有时失败。
AWS的原始文本(在此复制以防止Github问题消失):
...CloudFormation正在使用动作“apiateway:GetResources”进行API调用,以获得根资源ID。这对应于下面的API调用1。这是一个分页响应,意味着它一次只返回资源25 (默认情况下)。此外,为了防止节流和超时问题,只检查8页的深度。这意味着,这个根资源ID必须在前200个响应中才能得到根资源ID。否则,它将无法得到这个值。
..。
服务团队意识到了这个问题,并正在研究解决这个问题的方法。但是,没有ETA可供使用。
来源:https://github.com/serverless/serverless/issues/9036#issuecomment-1047240189
https://stackoverflow.com/questions/73776368
复制相似问题