AWS SDK for Ruby
Developer Guide

Getting Information about All Amazon EC2 Instances

The following example lists the IDs and states (pending, running, shutting down, terminated, stopping, or stopped) for all of your Amazon EC2 instances in the us-west-2 region.

require 'aws-sdk-ec2' # v2: require 'aws-sdk' ec2 = 'us-west-2') # To only get the first 10 instances: # ec2.instances.limit(10).each do |i| ec2.instances.each do |i| puts "ID: #{}" puts "State: #{}" end