Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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