Skip to content

Instantly share code, notes, and snippets.

@timhodson
Created May 10, 2018 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timhodson/0030e9568f310e2624bce4c1979727c0 to your computer and use it in GitHub Desktop.
Save timhodson/0030e9568f310e2624bce4c1979727c0 to your computer and use it in GitHub Desktop.
awslookup - add to your ~/.profile
# 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