Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AWS EC2の全イベント取得サンプル
module AWSOperation
def self.get_ec2_events(config = {})
report = []
config[:proxy_uri] ||= ENV['HTTP_PROXY'] || ENV['http_proxy']
ec2 = AWS::EC2.new(config)
ec2.regions.each do |region|
reg = ec2.regions[region.name]
reg.instances.each do |instance|
status = reg.client.describe_instance_status({"instance_ids" => [ instance.id ]})
event = status.data[:instance_status_set][0][:events_set] rescue nil
event = [] unless event
next if event.empty?
report << "ec2-instance[#{instance.tags["Name"] || instance.dns_name}] of #{region.name} has event #{event}"
end
end
report
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment