Skip to content

Instantly share code, notes, and snippets.

@hernandesbsousa
Forked from tsabat/deploy_utils.rb
Created April 13, 2016 16:46
Show Gist options
  • Save hernandesbsousa/a20e978e67b1f9cbad9fbf30adec442c to your computer and use it in GitHub Desktop.
Save hernandesbsousa/a20e978e67b1f9cbad9fbf30adec442c 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