Skip to content

Instantly share code, notes, and snippets.

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