Amazon web services 无服务器错误,当自定义命名资源需要替换时,CloudFormation无法更新堆栈

Amazon web services 无服务器错误,当自定义命名资源需要替换时,CloudFormation无法更新堆栈,amazon-web-services,amazon-dynamodb,amazon-cloudformation,serverless-framework,serverless,Amazon Web Services,Amazon Dynamodb,Amazon Cloudformation,Serverless Framework,Serverless,我有以下错误 无服务器:操作失败 Serverless Error --------------------------------------- An error occurred: phoneNumberTable - CloudFormation cannot update a stack when a custom-named resource requires replacing. Rename mysite-api-phonenumber-dev and update the sta

我有以下错误

无服务器:操作失败

Serverless Error ---------------------------------------
An error occurred: phoneNumberTable - CloudFormation cannot update a stack when a custom-named resource requires replacing. Rename mysite-api-phonenumber-dev and update the stack again…
我试图删除数据库,看看它是否可以重新创建它,但它仍然会给出相同的错误,并且不会重新创建数据库我在这里做什么?

我最近在serverless.yml文件中更改了以下资源

phoneNumberTable: #This table is used to track phone numbers used in the system
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: ${self:custom.phoneNumberTable}
        AttributeDefinitions: #UserID in this case will be created once and constantly updated as it changes with status regarding the user.
          - AttributeName: phoneNumber
            AttributeType: S
        KeySchema:
          - AttributeName: phoneNumber
            KeyType: HASH
        ProvisionedThroughput:
            ReadCapacityUnits: ${self:custom.dynamoDbCapacityUnits.${self:custom.pstage}}
            WriteCapacityUnits: ${self:custom.dynamoDbCapacityUnits.${self:custom.pstage}}
在复制和粘贴时,我意外地使用userId创建了它,所以我将其更改为phoneNumber作为散列键,但更改现在不会反映出来

编辑::


我找到了一个解决方案,但很糟糕。如果我做sls删除——舞台开发,它将删除我舞台上的所有东西,但实际上所有东西。。。然后,我必须执行sls部署--让开发人员重新开始部署,同时清除数据库中的所有数据。。。一定有更好的办法。

AWS推荐的解决方案是重命名:

我发现我需要插入一些变量使其工作

环境变量:
USERS\u表:“USERS-${opt:stage,self:provider.stage}-${self:provider.environment.BUILD\u NUMBER}”

表名:
TableName:${self:provider.environment.USERS\u TABLE}

在我的代码中:

const existingUser=等待dynamoDb.get({
TableName:process.env.USERS\u表,
关键:{
电子邮件,
},
}).promise();

您的解决方案对我很好。。。阶段是“开发”,丢失的数据在我的案例中不是问题。谢谢在您的案例中,变量是否总是相同的?如果更改变量会发生什么情况?我最后不得不添加一个变量,该变量每次
BUILD\u NUMBER
都会更改。更新了我的答案。然而,我实际上决定切换到MySQL而不是Dynamo来完成我的工作。有趣的是,你提到我也切换到了MySQL,我有一些其他的帖子介绍了我是如何用serverlessNice实现自动化的。是的,我发现迪纳摩太有限了。我正在构建一个SaaS,我习惯于能够轻松地查询不同的字段并创建索引之类的东西。这不是一个解决方案,我的意思是这不是一个真正的解决方案,这基本上会删除现有的表,并丢失数据,如果我理解正确,您能解释问题的原因吗?我无法理解您提供的AWS页面中提到的解释。