Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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? :)

share|improve this question

2 Answers

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
share|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
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'))));
share|improve this answer
1  
If this solved your question, please mark it as such. – Bart De Vos Jun 4 '11 at 19:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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