123456789101112131415161718192021222324252627282930313233 |
- #! /bin/bash
- #
- # Usage:
- # FindInstanceInAccount.sh <instanceid> <accountname>
- if [ $# -ne 2 ]; then
- echo Usage: $0 "<searchstring> <profile>"
- exit 1
- fi
- # TODO: Sanitize search string
- SEARCHSTRING=$1
- PROFILE=$2
- # Cool, grab regions dynamically
- REGIONS=$(aws ec2 describe-regions --profile $PROFILE --output text --query 'Regions[*].RegionName')
- for region in $REGIONS; do
- (
- # Search by instance ID:
- aws ec2 describe-instances --profile $PROFILE --region $region --instance-id $SEARCHSTRING &> /dev/null && \
- echo "$SEARCHSTRING is in $region under profile $PROFILE"
- # Search by Name:
- aws ec2 describe-instances --profile $PROFILE --region $region --filter "Name=tag:Name,Values=$SEARCHSTRING" &> /dev/null && \
- echo "$SEARCHSTRING is in $region under profile $PROFILE"
- ) &
- done 2> /dev/null
- wait
|