概要
AWS Batchを記述したCloudformationテンプレートを更新したら、以下のエラーになりました。こちらの原因と対処法を解説します。
CloudFormation cannot update a stack when a custom-named resource requires replacing. Rename arn:aws:batch:ap-northeast-1:1234567890:compute-environment/xxxx-compute-environment and update the stack again.
原因
このエラーは、CloudFormationがカスタム名を持つリソースを置き換える必要がある場合に発生するもの。
今回で言うと、AWS Batchのcompute-environment
が該当します。
Batchのcompute-environment
の中身を少し変えたので、そうするとCloudFormationは新しいリソースを作成し、古いリソースを削除しようとしますが、カスタム名を持つリソースは直接置き換えることができない、という現象が起きていました。
対応
一時的にリソース名を変更すればスタックを更新できます。
Type: 'AWS::Batch::ComputeEnvironment'
のComputeEnvironmentName
のところですね。
もし元の名前に戻したい場合は再度その名前にしてスタックを更新すればOKです。