I have a group of EC2 instances in a security group. I am looking for a way to obtain a list of their public DNS address's from command line. I have a script that uses RSYNC to make sure a set of files is updated across these servers. They are in an elastic load balancer and the amount of servers in the group changes enough that I do not want to have to maintain the list by hand. I want to avoid using AWK or SED to pull information out of ec2-describes-instances, I'd prefer to use the API directly. Anybody have any great suggestions? :)

link|improve this question
feedback

2 Answers

up vote 2 down vote accepted

Incase anybody is searching for a solution, I ended up using Amazon's PHP SDK. It allows you to filter results by many different criteria. I simply did a describe instance request, filtering by a specific security group (where security-group-name is the one you want to search for!)

 // Get the response from a call to the DescribeInstances operation.
 $response = $ec2->describe_instances(array('Filter' => array(array('Name' => 'group-name
', 'Value' => 'security-group-name'))));
link|improve this answer
If this solved your question, please mark it as such. – Bart De Vos Jun 4 '11 at 19:51
feedback

The command line output format is pretty static, and you can control when it might changed because the toolkit is your hands. I keep a copy of the api tools in a versioned repository along with whatever software I've written that uses it, this way they always work together at a given version.

If you do decide to go this way, here is a simple grab to get the public DNS address of everything running. Obviously you could request this for a specific group too.

ec2-describe-instances | grep 'INSTANCE' | cut  -f 4
link|improve this answer
This doesn't really work because I want to grab only instances from a particular security group. It splits this information onto separate lines. – geekbri Apr 27 '11 at 22:18
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.