AWS SDK for Ruby
Developer Guide

Getting Information about All Amazon EC2 Instances with a Specific Tag Value

The following example lists the ID and state (pending, running, shutting down, terminated, stopping, or stopped) of an Amazon EC2 instance with the tag Group and tag value MyGroovyGroup in the us-west-2 region.


The tag name and value are case-sensitive.

require 'aws-sdk-ec2' # v2: require 'aws-sdk' ec2 = 'us-west-2') # Get all instances with tag key 'Group' # and tag value 'MyGroovyGroup': ec2.instances({filters: [{name: 'tag:Group', values: ['MyGroovyGroup']}]}).each do |i| puts 'ID: ' + puts 'State: ' + end