AWS Cloud spans 69 Availability Zones within 22 geographic regions around the world, with announced plans for 9 more Availability Zones and three more Regions in Cape Town, Jakarta, and Milan.
If you are using more than one region it takes much time to browse through all regions in a browser and check which instances are running.
To save time, we are using awscli command in a shell script which will list all instances from all regions. You can use multiple profile names.
You can specify multiple profile names as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#!/bin/bash for i in profile1 profile2 do OWNER_ID=`aws iam get-user --profile $i --output text | awk -F ':' '{print $5}'` tput setaf 2;echo "Profile : $i";tput sgr0 tput setaf 2;echo "OwnerID : $OWNER_ID";tput sgr0 for region in `aws --profile $i ec2 describe-regions --output text | cut -f4` do tput setaf 1;echo "Listing Instances in region $region";tput sgr0 aws ec2 describe-instances --query 'Reservations[*].Instances[*].[Tags[?Key==`Name`].Value , InstanceId]' --profile $i --region $region --output text done & done wait |
This will run jobs in parallel and exit when all jobs are completed.