Skip to content

Instantly share code, notes, and snippets.

@danielsiwiec
Created March 13, 2015 06:54
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 danielsiwiec/e91a24249d45b9d5df01 to your computer and use it in GitHub Desktop.
Save danielsiwiec/e91a24249d45b9d5df01 to your computer and use it in GitHub Desktop.
List and reboot AWS instances using Resource class
require 'aws-sdk'
require 'json'
creds = JSON.load(File.read('creds.json'))
creds = Aws::Credentials.new(creds['AccessKeyId'], creds['SecretAccessKey'])
ec2 = Aws::EC2::Resource.new(region:'us-west-1',credentials:creds)
ec2.instances.each do |instance|
puts "ID: #{instance.instance_id} State: #{instance.state.name} Hostname: #{instance.public_dns_name}"
instance.reboot
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment