我已经能够使用PHP SDK从我的所有EC2实例中检索完整的标签列表,但我很难将结果过滤到特定的实例......
// Collect instance information
$sInstanceId = file_get_contents('http://169.254.169.254/latest/meta-data/instance-id'); // 'i-52da5b1f'
$sAvailabilityZone = file_get_contents('http://169.254.169.254/latest/meta-data/placement/availability-zone'); // 'eu-west-1b'
$sRegion = preg_replace('/^(.*)([0-9]{1})([a-zA-Z]{1})/', '$1$2', $sAvailabilityZone);
use Aws\Common\Aws;
use Aws\Ec2\Command\DescribeTags;
use Aws\Common\Enum\Region;
// Set up the global AWS factory
$oAWS = Aws::factory(array(
'key' => CONST_AWS_ACCESS_KEY,
'secret' => CONST_AWS_SECRET_KEY,
'region' => $sRegion
));
// Query EC2 for tags
$oEC2Client = $oAWS->get('ec2');
$oModel = $oEC2Client->describeTags()->toArray();
我已经尝试将对talkTags的调用更改为...
$oModel = $oEC2Client->describeTags(array(
"Filters" => array(
array("Name" => "resource-id", "Value" => $sInstanceId)
)
))->toArray();
但这似乎没有任何区别。 有人可以帮我解释一下吗?
答案 0 :(得分:5)
API docs for Ec2Client.describeTags表明Value
实际应该是Values
并且应该是一个数组。请尝试以下方法:
$oModel = $oEC2Client->describeTags(array(
"Filters" => array(
array("Name" => "resource-id", "Values" => array($sInstanceId))
)
))->toArray();