Skip to content

Instantly share code, notes, and snippets.

@tsabat
Last active April 13, 2016 16:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tsabat/5890996 to your computer and use it in GitHub Desktop.
Save tsabat/5890996 to your computer and use it in GitHub Desktop.
A ruby script to get all instances with a given tags.
require 'aws-sdk'
require 'awesome_print'
class AwsUtil
def ec2_object
# deployer user, has read-only access
AWS::EC2.new(
access_key_id: "<your_key_here>",
secret_access_key: "<your_secret_here>",
region: 'us-west-2'
)
end
def deployed_app_server_dns_names
ec2_object.instances.
filter('tag:Role', 'app').
filter('tag:Environment', 'production').
filter('instance-state-name', 'running').
map {|r| r.dns_name}
end
def print_dns_names
ap deployed_app_server_dns_names
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment