削除した CloudFormation スタックの参照が ValidationError になったときの対処方法
困っていた内容
AWS CLI で CloudFormation のlist-stack-resourcesコマンドを実行しています。
スタックを削除したところ、ValidationErrorが発生するようになりました。
なぜでしょうか。削除されたスタックの情報は確認できないのでしょうか。
$ aws cloudformation list-stack-resources \
--stack-name hato-stack \
--query 'StackResourceSummaries[*].[LogicalResourceId,PhysicalResourceId,ResourceType,ResourceStatus]' \
--output table
An error occurred (ValidationError) when calling the ListStackResources operation: Stack with id hato-stack does not exist
どう対応すればいいの?
--stack-nameで「スタック ID」を指定してください。
# スタック ID
arn:aws:cloudformation:ap-northeast-1:123456789012:stack/hato-stack/12922010-a3e5-11f0-a00e-06cbfcfb8aa1
# 実行例
$ aws cloudformation list-stack-resources \
--stack-name arn:aws:cloudformation:ap-northeast-1:123456789012:stack/hato-stack/12922010-a3e5-11f0-a00e-06cbfcfb8aa1 \
--query 'StackResourceSummaries[*].[LogicalResourceId,PhysicalResourceId,ResourceType,ResourceStatus]' \
--output table
--------------------------------------------------------------------------------------------------
| ListStackResources |
+--------------------+-------------------------+------------------------------+------------------+
| NetworkInterface01| eni-0b2884e11048hato5 | AWS::EC2::NetworkInterface | DELETE_COMPLETE |
| NetworkInterface02| eni-0bab0hatob9f4e607 | AWS::EC2::NetworkInterface | DELETE_COMPLETE |
| NetworkInterface03| eni-0ahato0cba8d67f8d | AWS::EC2::NetworkInterface | DELETE_COMPLETE |
+--------------------+-------------------------+------------------------------+------------------+
スタックを削除した場合でも、最大 90 日間はリソースに関する情報を取得できます。
ただし、--stack-nameの指定において、スタック名(例:hato-stack)ではなく、スタック ID を指定する必要があります。
なお、削除したスタックの情報は、AWS マネジメントコンソールの場合、「ステータスのフィルター」で「削除済み」を選択すると表示できます。

参考資料
For deleted stacks, ListStackResources returns resource information for up to 90 days after the stack has been deleted.
…(中略)…
--stack-name (string) [required]
The name or the unique stack ID that is associated with the stack, which aren’t always interchangeable:
- Running stacks: You can specify either the stack’s name or its unique stack ID.
- Deleted stacks: You must specify the unique stack ID.








