Skip to content

Instantly share code, notes, and snippets.

@TonyFNZ
Created August 4, 2019 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TonyFNZ/dac9793ed59eb28e36798cd21c0cbe75 to your computer and use it in GitHub Desktop.
Save TonyFNZ/dac9793ed59eb28e36798cd21c0cbe75 to your computer and use it in GitHub Desktop.
The following code can be added to your `.bashrc` file to make it easy to run an AWS CLI command across all regions in your account. This is useful when searching for stray resources that may need to be cleaned up.
################################################################################################
# Add the following code to your .bashrc file to add the all-regions command to your terminal
# This code will run the specified command once for each AWS region you have access to
################################################################################################
all-regions () {
for region in `aws ec2 describe-regions --query "Regions[].RegionName" --output text`
do
echo "Region: $region..."
eval "$@ --region $region"
done
}
################################################################################################
# EXAMPLE USAGE:
# The following command will list all EC2 instances for your account in all AWS regions
#
# all-regions aws ec2 desribe instances
################################################################################################
# Example usage:
# $ all-regions aws ec2 desribe instances
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment