Skip to content

Instantly share code, notes, and snippets.

@Convicted202
Created April 6, 2019 12:32
Show Gist options
  • Save Convicted202/d685f2221f408bbe72a37c961e19354d to your computer and use it in GitHub Desktop.
Save Convicted202/d685f2221f408bbe72a37c961e19354d to your computer and use it in GitHub Desktop.
Grepping instances ips from autoscaling group
1. =>
#!/bin/bash
for i in `aws autoscaling describe-auto-scaling-groups --auto-scaling-group-name ASGName | grep -i instanceid | awk '{ print $2}' | cut -d',' -f1| sed -e 's/"//g'`
do
aws ec2 describe-instances --instance-ids $i | grep -i PrivateIpAddress | awk '{ print $2 }' | head -1 | cut -d"," -f1
done;
2. =>
aws ec2 describe-instances --region us-east-1 --instance-ids \
$(aws autoscaling describe-auto-scaling-instances --region us-east-1 --output text \
--query "AutoScalingInstances[?AutoScalingGroupName=='ASG_NAME'].InstanceId") \
--query "Reservations[].Instances[].PrivateIpAddress"
| jq -r '.[]' # for plain output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment