Skip to content

Instantly share code, notes, and snippets.

@EvgeniGordeev
Created September 26, 2017 16:41
Show Gist options
  • Save EvgeniGordeev/a397eea6426500237e8bf786c3c2058f to your computer and use it in GitHub Desktop.
Save EvgeniGordeev/a397eea6426500237e8bf786c3c2058f to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
aws_region=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/[a-z]$//')
aws configure set default.region $aws_region
aws configure set default.output json
describe_instances(){
local filter=$1
local region=${2:-$aws_region}
aws ec2 describe-instances --filters "Name=tag:Name,Values=$filter" "Name=instance-state-name,Values=running" \
--query "sort_by(Reservations[].Instances[].{
PrivateIp:NetworkInterfaces[0].PrivateIpAddress,
Name:Tags[?Key=='Name'] | [0].Value,
PublicIp:NetworkInterfaces[0].Association.PublicIp
}, &Name)" --region $region
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment