What is awsall CLI tool
This is a simple solution we have created to execute your AWS CLI
commands on all AWS regions without having to mention --region
argument all the time.
Let's say you want to list the instances as a table with selected fields but you want to do that for all the AWS regions.
Or let's suppose you want to list all your EC2 instances, Load Balancers or EFS or any AWS resources across all AWS regions.
You would usually choose to run the commands on a loop or specify the --region
and re run the commands.
With awsall. you dont have to do that. It will take care of re running your commands across the regions and get the desired results.
Where it can be used
This can be used on the workstations that supports linux shells. preferably bash
or zsh
I have tested this on the MAC and Linux distributions.
Prerequisites
- Functionining AWS CLI setup ( Refer this article if you are new to AWS CLI)
- Permission to modify your own user's
~/.bashrc
or~/.zshrc
file
How to install awsall
It is a simple solution which does not need any software installation or download.
Based on the shell you are using edit your ~/.bashrc
or ~/.zshrc
file
These files are executed when a user SSH in or launch a new terminal.
By Adding the following source code ( shell function ) into those files and re launching the terminal or by executing source ~/.bashrc
or source ~/.zshrc
the installation is complete.
Here is the script that you have to add
function awsall { export AWS_PAGER="" for i in `aws ec2 describe-regions – query "Regions[].{Name:RegionName}" – output text|sort -r` do echo "------" echo $i echo "------" echo -e "\n" if [ `echo "$@"|grep -i '\-\-region'|wc -l` -eq 1 ] then echo "You cannot use – region flag while using awsall" break fi aws $@ – region $i sleep 2 done trap "break" INT TERM }
You can add this function at the end of the bashrc or zshrc file.
How to use awsall
Once you have added this snippet and re launched or sourced your startup configuration file.
You can start using this as a replacement for aws
command only when you want the command to be executed on all regions
For example.
let's suppose you execute the following command to list the instances on your default region
aws ec2 describe-instances
you can simply replace aws
with awsall
to execute the same CLI command across all regions
awsall ec2 describe-instances
Let it be any complicated aws cli command like the ones you see here on the below article, with lot of filters and queries and formatting
AWS EC2 CLI List Examples – Describe instances | Devops Junction
awsall
would just execute it by just adding --region
flag automatically and run it across all the regions.
It works with literally any AWS CLI command like aws ec2
, aws efs
etc. so its not just EC2
How awsall works
All the hardworks and the commands are yours.
awsall
just takes care of executing the same command across all regions dynamically.
It basically get what you give after awsall
and replace it with aws
and append --region
argument to it and execute it across all regions in a loop with 2 seconds to sleep
between each region.
Since awsall automatically adds the
--region
argument to the command you have written. you cannot use awsall with – region argument.In that case. you can use just
aws
cli itself. If you want to execute a command on a specific regionawsall is not needed there anyway. is not it ?
How the region names are fetched
awsall executes the following aws cli command to get the regions from AWS itself
aws ec2 describe-regions – query "Regions[].{Name:RegionName}" – output text|sort -r
It is reverse sorted to keep the most used us-east
and us-west
on top.
A Quick Demo
Here is a quick Demo of me executing awsall
and showing how it works
How to Stop while the awsall is running
Before we go to conclusion, Sometimes we do not want to wait for awsall to complete all the regions.
In such cases. if you awsall to stop immediately. Please press CTRL+C twice. that should do it.
Conclusion
I know there are lot of tools like awless
and others that solve the aws CLI related problems better. But all the tools limit you to a region specific.
I thought awsall would solve that problem for all of us.
If you have any better idea or modification on this. please feel free to comment.
Cheers
Sarav AK
Follow me on Linkedin My Profile Follow DevopsJunction onFacebook orTwitter For more practical videos and tutorials. Subscribe to our channel
Signup for Exclusive "Subscriber-only" Content