Skip to content

Instantly share code, notes, and snippets.

@davidkelley
Last active August 29, 2015 14:17
Show Gist options
  • Save davidkelley/cc3c90123aeb640a8758 to your computer and use it in GitHub Desktop.
Save davidkelley/cc3c90123aeb640a8758 to your computer and use it in GitHub Desktop.
Retrieve comma-delimited list of Private IP addresses for EC2 instances in the same Autoscalinggroup
1. Describe tags for the instance itself and retrieve the autoscaling group name
GROUP=$(ec2-describe-tags --filter "resource-type=instance" --filter "resource-id=$(curl http://169.254.169.254/latest/meta-data/instance-id)" --filter "key=aws:autoscaling:groupName" | cut -f5)
2. Grab all the EC2 instance IDs for that autoscaling group
IDS=$(aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names $GROUP --query 'AutoScalingGroups[0].Instances[].InstanceId' --output text | sed 's/\t/ /g')
3. For each instance-id, grab the private IP address of the instance
IPS=$(aws ec2 describe-instances --instance-ids $IDS --region us-east-1 --query Reservations[].Instances[].PrivateIpAddress --output text | sed 's/\t/,/g')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment