Skip to content

Instantly share code, notes, and snippets.

@mechamogera
Created October 23, 2012 08:26
Show Gist options
  • Save mechamogera/3937629 to your computer and use it in GitHub Desktop.
Save mechamogera/3937629 to your computer and use it in GitHub Desktop.
起動中のEC2インスタンスを検出するスクリプト
gem 'aws-sdk'
require 'rubygems'
require 'aws-sdk'
ec2 = AWS::EC2.new(:access_key_id => nil,
:secret_access_key => nil,
:proxy_uri => ENV['HTTPS_PROXY'] || ENV['https_proxy'] || ENV['HTTP_PROXY'] || ENV['http_proxy'])
ec2.regions.each do |region|
reg = ec2.regions[region.name]
reg.instances.each do |instance|
if instance.status == :running
puts instance.tags["Name"] || instance.dns_name
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment