Created
December 5, 2023 04:12
-
-
Save adamcousins/216916cd294db69d77e8059fccf378cd to your computer and use it in GitHub Desktop.
List All Cloudformation Stacks Starting With in AWS Organisation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
STACK_NAME_PREFIX="alarm" | |
for acc in `aws organizations list-accounts --query 'Accounts[*].Id' --output text `; | |
do | |
echo "checking account $acc now";\ | |
OUT=$(aws sts assume-role --role-arn arn:aws:iam::$acc:role/OrganizationAccountAccessRole --role-session-name ckecking-account-$acc);\ | |
export AWS_ACCESS_KEY_ID=$(echo $OUT | jq -r '.Credentials''.AccessKeyId');\ | |
export AWS_SECRET_ACCESS_KEY=$(echo $OUT | jq -r '.Credentials''.SecretAccessKey');\ | |
export AWS_SESSION_TOKEN=$(echo $OUT | jq -r '.Credentials''.SessionToken'); | |
aws cloudformation list-stacks --query "StackSummaries[?starts_with(StackName, '$STACK_NAME_PREFIX')].StackName" --stack-status-filter "CREATE_COMPLETE" "UPDATE_COMPLETE" | |
echo "checking account $acc completed";\ | |
unset AWS_ACCESS_KEY_ID;\ | |
unset AWS_SECRET_ACCESS_KEY;\ | |
unset AWS_SESSION_TOKEN;\ | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment