15

次のエラーがあります。

サーバーレス: 操作に失敗しました!

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 を実行してデプロイをやり直す必要があります。その間、データベースはすべてクリアされますデータ...どうにかしてより良い方法が必要です。

4

2 に答える 2

11

AWS が推奨する解決策は、名前を変更することです: https://aws.amazon.com/premiumsupport/knowledge-center/cloudformation-custom-name/

于 2017-11-30T19:23:03.553 に答える