Browse Source

Works with instanceid

Fred Damstra 9 years ago
parent
commit
ce70565690
1 changed files with 28 additions and 0 deletions
  1. 28 0
      FindInstanceInProfile.sh

+ 28 - 0
FindInstanceInProfile.sh

@@ -0,0 +1,28 @@
+#! /bin/bash
+#
+# Usage:
+#  FindInstanceInAccount.sh <instanceid> <accountname>
+
+if [ $# -ne 2 ]; then
+	echo Usage: $0 "<instanceid> <profile>"
+	exit 1
+fi
+
+INSTANCEID=$1
+PROFILE=$2
+
+# Cool, grab regions dynamically
+REGIONS=$(aws ec2 describe-regions --profile $PROFILE --output text --query 'Regions[*].RegionName')
+
+for region in $REGIONS; do
+	(
+	         aws ec2 describe-instances --profile $PROFILE --region $region --instance-id $INSTANCEID &> /dev/null && \
+			 echo "$INSTANCEID is in $region under profile $PROFILE"
+	) &
+done 2> /dev/null
+
+wait 
+
+
+
+