Created
September 26, 2017 16:41
-
-
Save EvgeniGordeev/a397eea6426500237e8bf786c3c2058f to your computer and use it in GitHub Desktop.
This file contains 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
#!/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