您好我已经开始使用aws,并发现我们可以得到aws php sdk运行服务器的列表。 有没有其他的方式来获得所有ec2实例的列表? 获取列表后,我想同步从一个主要实例的数据到所有的实例。 点击button之类的东西也可以进行操作。 是rsync,incron唯一的select,也可以由aws php sdk来完成。 请提供一些教程链接。
我想你会使用AWS的PHP SDK;
http://aws.amazon.com/sdkforphp/
运行入门指南来设置您的密钥;
http://aws.amazon.com/articles/4261?_encoding=UTF8&jiveRedirect=1
然后使用describe_instances函数来收集一个实例数组;
http://docs.amazonwebservices.com/AWSSDKforPHP/latest/#m=AmazonEC2/describe_instances
它看起来像你可以构造和过滤只返回正在运行的实例,或者然后循环返回像使用describe_instance_status函数获得更详细的信息;
http://docs.amazonwebservices.com/AWSSDKforPHP/latest/#m=AmazonEC2/describe_instance_status
喜欢以下的东西将工作…
<?php require_once "/home/XXX/src/php-aws-sdk-1.5.3/sdk.class.php"; CFCredentials::set(array( 'testing' => array( 'key' => 'XXX', 'secret' => '+YYY+', 'default_cache_config' => '', 'certificate_authority' => false ), // Specify a default credential set to use if there are more than one. '@default' => 'testing' )); $ec2 = new AmazonEC2(); $response = $ec2->describe_instances(array( "Filter" => array( array("Name"=>"instance-state-code", "Value" => "16")))); foreach($response as $res){ var_dump( $res ); } ?>
实例状态码16是用于“运行”