Last active
July 7, 2023 04:55
-
-
Save junaidk/433345da5bf8e580680d9109792d3169 to your computer and use it in GitHub Desktop.
Get List of EC2 instances from All regions
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
# 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 |
If you don't have the defaults set cut f3 works, if you do use cut f4
its works thanks
aws ec2 describe-regions --output text --query 'Regions[].RegionName'
Name:Tags[0].Value > Name:Tags[?Key=='Name']|[0].Value
The first tag may be different.
Hi Everyone,
How to export that output to excel format?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jake9696
Thanks for pointing it out.
I have updated it.