Created
May 10, 2018 12:22
-
-
Save timhodson/0030e9568f310e2624bce4c1979727c0 to your computer and use it in GitHub Desktop.
awslookup - add to your ~/.profile
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
# uses aws cli to lookup instances based on a filter on the Name tag | |
# $1 is the profile to use | |
# $2 is the filter to use | |
# $3 is optional, the value doesn't matter but if passed in will result | |
# in this function printing out the raw command its about to run | |
# for debugging purposes | |
awslookup() { | |
cmd="aws --profile $1 ec2 describe-instances --filters \"Name=tag:Name,Values=$2\" --query 'Reservations[].Instances[].[InstanceId,PublicDnsName,PrivateDnsName,State.Name,InstanceType,join(\`,\`,Tags[?Key==\`Name\`].Value)]' --output table" | |
if [ $# -eq 3 ] | |
then | |
echo "Running $cmd" | |
fi | |
eval $cmd | |
} | |
alias awslookup=awslookup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment