Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Is there a utility or script available to retrieve a list of all instances from AWS EC2 auto scale group?

I need a dynamically generated list of production instance to hook into our deploy process. Is there an existing tool or is this something I am going to have to script?

like image 611
James McMahon Avatar asked Mar 20 '14 13:03

James McMahon


People also ask

How do I get a list of EC2 instances?

To see all running instances go to EC2 or VPC console and click EC2 Global View in the top left corner. Save this answer.

How do I monitor Auto Scaling in a group?

Open the Amazon EC2 console at console.aws.amazon.com/ec2/. From the navigation pane, select Auto Scaling Groups > (select your group). From the Monitoring tab, select Auto Scaling Metrics > Enable Group Metrics Collection or Display > Auto Scaling.

How many EC2 instances can you have in an Auto Scaling group?

If you specify scaling policies, then Amazon EC2 Auto Scaling can launch or terminate instances as demand on your application increases or decreases. For example, the following Auto Scaling group has a minimum size of one instance, a desired capacity of two instances, and a maximum size of four instances.


2 Answers

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

like image 111
Sébastien Stormacq Avatar answered Oct 09 '22 06:10

Sébastien Stormacq


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.

like image 42
David Levesque Avatar answered Oct 09 '22 06:10

David Levesque