Skip to content

Instantly share code, notes, and snippets.

@dazl
Created November 11, 2015 03:20
Show Gist options
  • Save dazl/2ba10cb4050098f70b6a to your computer and use it in GitHub Desktop.
Save dazl/2ba10cb4050098f70b6a to your computer and use it in GitHub Desktop.
get IP numbers of instances behind an AWS ELB
#!/bin/bash
display_usage() {
echo -e "\nUsage:\n$0 <load-balancer-name> [<region>] \n"
}
if [ $# -lt 1 ]
then
display_usage
exit 1
fi
for i in `aws --region ${2-us-west-2} elb describe-instance-health --load-balancer-name $1 | grep -i instanceid | awk '{ print $2}' | cut -d',' -f1| sed -e 's/"//g'`
do
aws --region ${2-us-west-2} ec2 describe-instances --instance-ids $i | grep -i PrivateIpAddress | awk '{ print $2 }' | head -1 | cut -d"," -f1
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment