Last active
June 9, 2017 21:58
-
-
Save dreamnite/a38a6494afd467e5466832252cacee68 to your computer and use it in GitHub Desktop.
find instances by name
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
array_of_zones = Aws::EC2::Client.new().describe_availability_zones.availability_zones.map { |x| x.zone_name } |
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' | |
client = Aws::EC2:Client.new() | |
i = [] | |
found_nodes = [] | |
find_list = %w(name name name) | |
client.describe_instances[0].each { |x| i.push(x.instances.first) } | |
find_list.each |find_me| | |
i.each { |x| x.tags.each { |y| found_nodes.push(x) if y.value =~ %r(^#{find_me}$)} | |
end | |
# Found nodes now contains all information about the instances you are looking for | |
# Getting a map of the instance ids to work with | |
found_nodes.map {|x| x.instance_id } # ['i-xxx', 'i-yyy',... ] | |
#stopping instances of the found nodes | |
client.stop_instances(instance_ids: found_nodes.map {|x| x.instance_id } ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment