无服务器共享API网关部署到不同阶段时出错

问题描述 投票:2回答:1

我正在使用无服务器版本1.29.2

我创建了一个初始的cloudformation脚本,它创建了一个将由其他服务使用的API GateWay REST API。所以这是负责它的cloudformation脚本。

{
   "AWSTemplateFormatVersion":"2010-09-09",
   "Description":"API",
   "Resources":{
      "APIGw":{
         "Type":"AWS::ApiGateway::RestApi",
         "Properties":{
            "Name":"API-GW"
         }
      }
   },
   "Outputs":{
      "ApiGwRestApiId":{
         "Value":{
            "Ref":"APIGw"
         },
         "Export":{
            "Name":"apigw-restApiId"
         }
      },
      "eyesApiGwRestApiRootResourceId":{
         "Value":{
            "Fn::GetAtt":[
               "APIGw",
               "RootResourceId"
            ]
         },
         "Export":{
            "Name":"apigw-rootResourceId"
         }
      }
   }
}

这是我尝试部署的应用程序的serverless.yml。

service: template-test-service

provider:
  name: aws
  runtime: python3.6
  region: eu-central-1
  stage: ${self:custom.environment.stage}
  environment:
    stage: ${self:custom.environment.stage}
  apiGateway:
    restApiId:
      'Fn::ImportValue': apigw-restApiId
    restApiRootResourceId:
      'Fn::ImportValue': apigw-rootResourceId

当我执行sls deploy --stage dev一切正常,但是当我执行另一个部署到sls deploy --stage prod

出现此错误。

Another resource with the same parent already has this name
amazon-web-services serverless api-gateway
1个回答
-1
投票

看看Serverless documentation on sharing API Gateway了吗?

看来你必须创建公共资源路径组件才是CloudFormed对象

© www.soinside.com 2019 - 2024. All rights reserved.