AWS API: Proper syntax for filtering by tag name and value (e.g. describeInstances)
It took me quite a while to figure out the right syntax for filtering instances by tag name and value in the AWS EC2 API's describeInstances.
The documentation is not exactly crystal-clear to me:
Anyway, here is the proper syntax, provided we are interested in the tag elasticbeanstalk:environment-name:
So the name of the tag is embedded in the Name part and not, as I initially understood,
Credit: garnaat.
The documentation is not exactly crystal-clear to me:
tag
:key=value - The key/value combination of a tag assigned to the resource, wheretag
:key is the tag's key.
Anyway, here is the proper syntax, provided we are interested in the tag elasticbeanstalk:environment-name:
var params = {
Filters: [
{
Name: 'tag:elasticbeanstalk:environment-name',
Values: ['mySuperApp']
}
]
};
ec2.describeInstances(params);
So the name of the tag is embedded in the Name part and not, as I initially understood,
{ Name: 'tag', Values: ['elasticbeanstalk:environment-name=mySuperApp'] }
Credit: garnaat.