Getting a list of instances in an EC2 auto scale group?

You can also use below command to fetch private ip address without any jq/awk/sed/cut

$ aws autoscaling describe-auto-scaling-instances --region us-east-1 --output text \
--query "AutoScalingInstances[?AutoScalingGroupName=='ASG-GROUP-NAME'].InstanceId" \
| xargs -n1 aws ec2 describe-instances --instance-ids $ID --region us-east-1 \
--query "Reservations[].Instances[].PrivateIpAddress" --output text

courtesy this


You can use the describe-auto-scaling-instances cli command, and query for your autoscale group name.

Example:

aws autoscaling describe-auto-scaling-instances --region us-east-1 --query 'AutoScalingInstances[?AutoScalingGroupName==`YOUR_ASG`]' --output text

Hope that helps


Here is a bash command that will give you the list of IP addresses of your instances in an AutoScaling group.

for ID in $(aws autoscaling describe-auto-scaling-instances --region us-east-1 --query AutoScalingInstances[].InstanceId --output text);
do
aws ec2 describe-instances --instance-ids $ID --region us-east-1 --query Reservations[].Instances[].PublicIpAddress --output text
done

(you might want to adjust the region and to filter per AutoScaling group if you have several of them)

On a higher level point of view - I would question the need to connect to individual instances in an AutoScaling Group. The dynamic nature of AutoScaling would encourage you to fully automate your deployment and admin processes. To quote an AWS customer : "If you need to ssh to your instance, change your deployment process"

--Seb


The describe-auto-scaling-groups command from the AWS Command Line Interface looks like what you're looking for.

Edit: Once you have the instance IDs, you can use the describe-instances command to fetch additional details, including the public DNS names and IP addresses.