Created
February 20, 2019 16:15
-
-
Save dgulinobw/94e174d337b92eff11b92d9681b3e308 to your computer and use it in GitHub Desktop.
ec2_instance_name_from_id.sh
This file contains hidden or 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
| #!/bin/bash | |
| InstanceId=$1 | |
| #for region in `aws ec2 describe-regions --output text | cut -f3` #unoptimized list order | |
| for region in us-east-1 us-east-2 us-west-1 us-west-2 eu-north-1 ap-south-1 eu-west-3 eu-west-2 eu-west-1 ap-northeast-2 ap-northeast-1 sa-east-1 ca-central-1 ap-southeast-1 ap-southeast-2 eu-central-1; | |
| do | |
| Name=$(aws ec2 describe-instances --region $region --instance-ids=$InstanceId | jq -r '.Reservations[].Instances[].Tags[] | select(.Key=="Name").Value') | |
| if [ "$Name" != "" ]; | |
| then | |
| echo $Name | |
| break | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment