Last active
December 20, 2015 06:49
-
-
Save petems/6088973 to your computer and use it in GitHub Desktop.
How to mass delete all EC2 instances, useful to run on a cron if you're paranoid about leaving stuff on all the time...
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
# Get these from https://console.aws.amazon.com/iam/home?#security_credential | |
export AMAZON_ACCESS_KEY_ID=FOO | |
export AMAZON_SECRET_ACCESS_KEY=BAR | |
export EC2_REGION="eu-west-1" |
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 'fog' | |
#Either source .aws_stuff or add it to .bashrc etc | |
@credentials = { | |
:provider => 'AWS', | |
:aws_access_key_id => ENV['AMAZON_ACCESS_KEY_ID'], | |
:aws_secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY'], | |
:region => ENV['EC2_REGION'], | |
} | |
def connection | |
@connection ||= Fog::Compute.new(@credentials) | |
end | |
connection.servers.all.each do |server| | |
puts server.id | |
puts "Destroying server now!" | |
server.destroy | |
puts "#{server.id} destroyed successfully" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment