Organization配下の全てのAWSアカウントのIDを取得
aws organizations list-accounts --query 'Accounts[].[Id]' --output text
特定のスタックセット内の全てのスタックインスタンスについてAWSアカウントのIDを取得
aws cloudformation list-stack-instances --stack-set-name STACK_SETS_NAME_HERE --query 'Summaries[].[Account]' --output text
応用例 CloudFormationのデプロイ先アカウントの指定に使える形式として出力する
スタックセットを消す前に、まずスタック内のすべてのスタックインスタンスを削除するためなどに利用。
aws cloudformation list-stack-instances --stack-set-name STACK_SETS_NAME_HERE --query 'Summaries[].[Account]' --output text | paste -sd,
出力例
000000000000,1111 1111 1111,222222222222,333333333333