如何以编程方式获得一个实例的公共DNS? [英] How to programmatically get public dns of an instance?

查看:157
本文介绍了如何以编程方式获得一个实例的公共DNS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用,以获得一个EC2实例的公共DNS PHP亚马逊SDK(或Amazon的API命令行工具)?

我想这个PHP code(等等),但它不会工作:

  require_once'/full/path/sdk.class.php;
$ EC2 =新AmazonEC2();
$响应= $ ec2-> describe_regions();
的print_r($响应);
 

和也

  require_once'/full/path/sdk.class.php;
$ EC2 =新AmazonEC2();
$响应= $ ec2-> describe_instances(阵列(
    '过滤器'=>阵列(
        阵列(名称=>的可用性区','价值'=>欧盟 - 西-1)
    )
));

的print_r($响应);
 

但我看不到公共DNS响应中的

解决方案

显然,你想找回自己的亚马逊在区域欧盟 - 西-1 EC2 实例(不是可用性区域顺便说一句正确的值。)。但是,你不指定任何地区的所有服务默认为美东地区的,请参阅AWS团队应对相关问题的 describeInstances()只给我的实例在美国东部

  

虽然你不能抢在一个呼吁所有区域的数据,你可以   调用describe_instances()方法在每个区域

  $ EC2 =新AmazonEC2();
$ ec2-> set_region(AmazonEC2 :: REGION_US_W1); //美西1

$响应= $ ec2-> describe_instances();
 

使用这个code与合适的常量供你选择的区域(如 AmazonEC2 :: REGION_EU_W1 )应该得到期望的结果。

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:

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.

这篇关于如何以编程方式获得一个实例的公共DNS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆