I have been able to retrieve a full list of tags from all my EC2 instances using the PHP SDK but I'm struggling to filter the results down to a particular instance...
// 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();
I've tried changing the call to describeTags to...
$oModel = $oEC2Client->describeTags(array(
"Filters" => array(
array("Name" => "resource-id", "Value" => $sInstanceId)
)
))->toArray();
But that seems to make no difference. Could someone shed some light on this for me please?