Skip to content

Instantly share code, notes, and snippets.

@adamcousins
Created January 20, 2025 05:46
Show Gist options
  • Save adamcousins/6f94a1846e96a3f16b4a46f4bab0db11 to your computer and use it in GitHub Desktop.
Save adamcousins/6f94a1846e96a3f16b4a46f4bab0db11 to your computer and use it in GitHub Desktop.
#!/bin/bash
accs=$(aws organizations list-accounts --query 'Accounts[*].Id' --output text)
for acc in $accs;
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');
# Get a list of all AWS regions
regions=$(aws ec2 describe-regions --query 'Regions[].RegionName' --output text)
# Iterate over each region and delete the Resource Explorer index
for region in $regions; do
echo "Deleting Resource Explorer index in $region..."
# AWS CLI command to delete the Resource Explorer index (this is a placeholder as the specific command may vary)
aws resource-explorer delete-index --region "$region" || echo "No Resource Explorer index to delete in $region or deletion failed."
done
echo "Completed deletion of Resource Explorer indexes in all regions."
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