Last active
February 20, 2019 15:59
-
-
Save dgulinobw/9a0ee6a142d6b3ae8e43b9967b2a95ee to your computer and use it in GitHub Desktop.
ec2_instance_id_from_name.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 | |
| InstanceName=$1 | |
| #for region in `aws ec2 describe-regions --output text | cut -f3` #unoptimized list order, but dynamic | |
| 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 | |
| Id=$(aws ec2 describe-instances --region $region --filters Name=tag-value,Values=$InstanceName | jq -r .Reservations[].Instances[].InstanceId) | |
| if [ "$Id" != "" ]; | |
| then | |
| echo $Id | |
| break | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment