-
-
Save hernandesbsousa/a20e978e67b1f9cbad9fbf30adec442c to your computer and use it in GitHub Desktop.
A ruby script to get all instances with a given tags.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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