CloudFormation cannot update a stack when a custom-named resource requires replacing
Serverlessフレームワークを使って作成していたDynamoDBテーブルのプライマリーキーを変更してsls deployしたら、こんなエラーが出た。
An error occurred: DynamoDbTable - CloudFormation cannot update a stack when a custom-named resource requires replacing. Rename hoge-events-dev and update the stack again..
同じ名前のままスキーマを変更することはできないようだ。
# serverless.yml
resources:
Resources:
DynamoDbTable:
Type: 'AWS::DynamoDB::Table'
Properties:
AttributeDefinitions:
-
AttributeName: year_month
AttributeType: S
KeySchema:
-
AttributeName: year_month
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: hoge-events-${self:provider.stage} # ここを適当な名前に変える
TableNameを適当な名前に変えて(末尾に-1をつけた)、sls deploy。
成功。これで古いテーブルは消えたので、元の名前に戻して再度デプロイしたら、新しいスキーマでのテーブル作成が完了。