Created
June 13, 2014 21:12
-
-
Save pasquinis/f04cd06fb691249cb966 to your computer and use it in GitHub Desktop.
Simple way to terminate an IT environment into AWS
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 'rubygems' | |
require 'aws-sdk' | |
secret_access_key = ENV['AWS_SECRET_KEY'] | |
access_key_id = ENV['AWS_ACCESS_KEY'] | |
config = { | |
:access_key_id => access_key_id, | |
:secret_access_key => secret_access_key, | |
:region => 'eu-west-1', | |
:log_level => 'debug' | |
} | |
AWS.config(config) | |
ec2 = AWS.ec2 | |
ec2.instances.with_tag('Environment','it').each do |obj| | |
obj.tags.each do |key,value| | |
puts "#{key} #{value}" | |
end | |
if obj.status == 'running' | |
puts "#{obj.status} #{obj.availability_zone} #{obj.private_ip_address} #{obj.launch_time} #{obj.instance_type} #{obj.id} " | |
obj.terminate | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment