我有以下错误。
无服务器:操作失败!
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 remove --stage dev 它将删除我的阶段的所有内容,但实际上所有内容......然后我必须执行 sls deploy --stage dev 重新开始部署,同时我的数据库被清除所有数据...必须有更好的方法。