Get List of EC2 instances from All regions
# install aws cli first and configure it with credentials and default region | |
# the script will iterate over all regions of AWS | |
for region in `aws ec2 describe-regions --output text | cut -f4` | |
do | |
echo -e "\nListing Instances in region:'$region'..." | |
aws ec2 describe-instances --query "Reservations[*].Instances[*].{IP:PublicIpAddress,ID:InstanceId,Type:InstanceType,State:State.Name,Name:Tags[0].Value}" --output=table --region $region | |
done |
This comment has been minimized.
This comment has been minimized.
dgacias
commented
Feb 9, 2018
It works as expected, but i had to execute first "aws configure" with empty values on everything except the region, because if you do not have any default region, the CLI complaints it does not know in which region work even when executing "aws ec2 describe-regions" alone. |
This comment has been minimized.
This comment has been minimized.
eguven
commented
Aug 13, 2018
@dgacias just export values before the loop export AWS_PROFILE=<YOUR-PROFILE>
export AWS_DEFAULT_REGION=<SOME-REGION> |
This comment has been minimized.
This comment has been minimized.
royharoush
commented
Dec 9, 2018
you're d man ! |
This comment has been minimized.
This comment has been minimized.
jake9696
commented
Nov 11, 2019
FYI, you need to change the "cut -f3" to "cut -f4" now as AWS added another field to the describe-regions output. |
This comment has been minimized.
This comment has been minimized.
@jake9696 |
This comment has been minimized.
This comment has been minimized.
fcp999
commented
Nov 17, 2019
If you don't have the defaults set cut f3 works, if you do use cut f4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
ojotoxy commentedJan 22, 2018
it works!