FindInstanceInProfile.sh 557 B

12345678910111213141516171819202122232425262728
  1. #! /bin/bash
  2. #
  3. # Usage:
  4. # FindInstanceInAccount.sh <instanceid> <accountname>
  5. if [ $# -ne 2 ]; then
  6. echo Usage: $0 "<instanceid> <profile>"
  7. exit 1
  8. fi
  9. INSTANCEID=$1
  10. PROFILE=$2
  11. # Cool, grab regions dynamically
  12. REGIONS=$(aws ec2 describe-regions --profile $PROFILE --output text --query 'Regions[*].RegionName')
  13. for region in $REGIONS; do
  14. (
  15. aws ec2 describe-instances --profile $PROFILE --region $region --instance-id $INSTANCEID &> /dev/null && \
  16. echo "$INSTANCEID is in $region under profile $PROFILE"
  17. ) &
  18. done 2> /dev/null
  19. wait