I am trying to get EC2 instances by tag via PHP. I can create servers with tags, I can get servers with tag data, but if what I want to do is get one of these tags, I canβt find examples.
It works:
if ($server_group != '') $filter[] = array('Name' => 'tag-value','Value' => $server_group); $response = $ec2->describe_instances(array('Filter' => $filter));
However, the problem is that it will find any tag with the value that I assigned to the $ server_group variable, whether the tag is correct or not. I can, of course, just be careful about how I assign tag values, but this is not bullet proof.
Alternative syntax is explained in the docs:
Example. To specify only those resources to which the Navalue = X tag has been assigned, specify:
Filter.1.Name=tag:Purpose Filter.1.Value.1=X
However, they do not give examples. I thought it would be:
$filter[] = array('Filter.1.Name','Value' => 'tag:Group'); $filter[] = array('Name' => 'Filter.1.Value.1','Value' => $server_group);
However, this does not seem to work - I received nothing.
Has anyone done this? Is there a working example that they can use? Perhaps I did not ask the right questions on Google - there are many examples of how to create tags, but not how to get them.