Skip to content

Instantly share code, notes, and snippets.

@ukn
Last active October 27, 2016 16:00
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 ukn/0b0687c34f03254b7de331551a8c86ab to your computer and use it in GitHub Desktop.
Save ukn/0b0687c34f03254b7de331551a8c86ab to your computer and use it in GitHub Desktop.
bash function that formats `aws ec2 describe-instances` into something readable
awsls(){
if [ -z ${1+x} ]; then
temp=`aws ec2 describe-instances`
else
temp=`aws ec2 describe-instances --profile ${1}`
fi
# All tags version
# aws ec2 describe-instances | jq -r '.Reservations[].Instances[] | | select (.State.Name != "terminated") | .InstanceId + "\t" + .PrivateIpAddress + "\t" + .PublicIpAddress + "\t" + .InstanceType + "\t" + (reduce.Tags[] as $tag (""; . + $tag.Key + "=" + $tag.Value + " "))'
echo $temp | jq -r '.Reservations[].Instances[] | select (.State.Name != "terminated") | .InstanceId + "\t" + .PrivateIpAddress + "\t" + ( if .PublicIpAddress then .PublicIpAddress else "\t" end) + "\t" + .InstanceType + "\t" + .State.Name + "\t " + (.Tags[] | select(.Key == "Name") | .Key + ":" + .Value)'
unset temp
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment