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
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:Using this code with the appropriate constant for your region of choice (e.g.
AmazonEC2::REGION_EU_W1
) should yield the desired result.If you're running this on the instance itself, you can hit AWS's internal metadata endpoint:
http://169.254.169.254/latest/meta-data/
will give you a list of the various metadata available to you. Currently: