Skip to content

Instantly share code, notes, and snippets.

@pasquinis
Created June 13, 2014 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pasquinis/f04cd06fb691249cb966 to your computer and use it in GitHub Desktop.
Save pasquinis/f04cd06fb691249cb966 to your computer and use it in GitHub Desktop.
Simple way to terminate an IT environment into AWS
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