How do I get a list of servers and their public DNS with Amazon EC2

Solution 1:

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

Solution 2:

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'))));