Skip to content

Instantly share code, notes, and snippets.

@dazl
Created November 25, 2015 00:48
Show Gist options
  • Save dazl/bcd57faa57937bb91c67 to your computer and use it in GitHub Desktop.
Save dazl/bcd57faa57937bb91c67 to your computer and use it in GitHub Desktop.
get IP numbers of instances in an AWS auto scaling group
#!/bin/bash
display_usage() {
echo -e "\nUsage (default region is us-west-2):\n\n $0 <auto-scaling-group-name> [<region>] \n"
}
if [ $# -lt 1 ]
then
display_usage
exit 1
fi
for i in `aws --region ${2-us-west-2} autoscaling describe-auto-scaling-groups --auto-scaling-group-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