How to programmatically get public dns of an instance?

amazon-ec2, amazon-web-services, php

Solution

Apparently you'd like to retrieve your Amazon EC2 instance in region `eu-west-1` (which isn't a correct value for 'availability-zone' btw.). However, you are not specifying any region and all services default to the US-East region, see the AWS team response to the related question describeInstances() is only giving me instances in us-east:

While you can't grab data for all regions in a single call, you can call the describe_instances() method in each region.

$ec2 = new AmazonEC2();
$ec2->set_region(AmazonEC2::REGION_US_W1); // US-West 1

$response = $ec2->describe_instances();

Using this code with the appropriate constant for your region of choice (e.g. `AmazonEC2::REGION_EU_W1`) should yield the desired result.

Problem

Is there a way to get the public DNS of an EC2 instance using PHP amazon SDK (or amazon's API command line tools)? I tried this PHP code (among others) but it won't work: ``` require_once '/full/path/sdk.class.php'; $ec2 = new AmazonEC2(); $response = $ec2->describe_regions(); print_r($response); ``` and also ``` require_once '/full/path/sdk.class.php'; $ec2 = new AmazonEC2(); $response = $ec2->describe_instances(array( 'Filter' => array( array('Name' => 'availability-zone', 'Value' => 'eu-west-1') ) )); print_r($response); ``` but I can't see the public dns in the response

Original source