Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

AWS API: Proper Syntax for Filtering by Tag Name and Value (e.g. describeInstances)

DZone's Guide to

AWS API: Proper Syntax for Filtering by Tag Name and Value (e.g. describeInstances)

· Cloud Zone ·
Free Resource

Container Monitoring and Management eBook: Read about the new realities of containerization.

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:

  • tag:key=value – The key/value combination of a tag assigned to the resource, where tag: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.

The Essentials of Container Monitoring: Learn the 4 principles of application containerization. Download Now.

Topics:
cloud ,api ,aws

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}