首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无服务器框架错误:单一API网关项目-- API网关的RootResourceId属性RestAPI <id>不存在

无服务器框架错误:单一API网关项目-- API网关的RootResourceId属性RestAPI <id>不存在
EN

Stack Overflow用户
提问于 2022-09-19 16:12:50
回答 1查看 182关注 0票数 0

我在使用CloudFormation使用Serverless框架在AWS中部署应用程序时遇到了问题。

我正在使用“单一API网关项目”策略进行部署。我将我的后端划分为服务,每个服务都有自己的目录在回购和serverless.yml文件中。

为了为其中每一个创建一个API,我首先部署一个根服务,它为我创建上述API,输出-- ApiGatewayRestApiIdApiGatewayRestApiRootResourceId --正如我在同一服务器无服务器框架的以下文档中所看到的:

https://www.serverless.com/framework/docs/providers/aws/events/apigateway#easiest-and-cicd-friendly-example-of-using-shared-api-gateway-and-api-resources

创建API网关的根服务如下所示:

代码语言:javascript
运行
复制
...
resources:
  Outputs:
    ApiGatewayRestApiId:
      Value:
        Ref: ApiGatewayRestApi
      Export:
        Name: ${self:provider.stage}-ApiGatewayRestApiId
    ApiGatewayRestApiRootResourceId:
      Value:
        Fn::GetAtt: 
          - ApiGatewayRestApi
          - RootResourceId
      Export:
        Name: ${self:provider.stage}-ApiGatewayRestApiRootResourceId
...

然后,从其他微服务中导入这些值​​,如下所示:

代码语言:javascript
运行
复制
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

  • Framework版本: 1.60.0

  • PluginVersion: 3.8.4

  • SDK版本: 2.3.2

  • Components核心版本: 1.1.2

  • Components CLI版本: 1.6.0
EN

回答 1

Stack Overflow用户

发布于 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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73776368

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档