Reputation: 979
I"m attempting to retrieve amazon generated events for my instances using ruby's aws-sdk. This will come in handy as I'm monitoring my instances and will alert when an event is found.
I found an article that will allow this using python's boto library but I'm currently constrained to using ruby.
These events can be found under EC2 Dashboard -> Events.
The current event that is showing that an instance is running on degraded hardware and will be retired. The event type is "instance-stop".
Is there a way to programmatically fetch these events using ruby's aws-sdk?
Upvotes: 1
Views: 427
Reputation: 979
I discovered this while poking around in the documentation for the ruby sdk on amazon's website and looking at someone's python code. They were making this call:
Python's boto library:
stats = ec2.get_all_instance_status()
In ruby and from the ec2 object, there does not exist a method like this exact call. I read further on this blog( http://ruby.awsblog.com/ ) and it shows examples but nothing quite similar to what I was wanting.
I was fumbling around in IRB when I noticed that there is a Client object and it does include the 'describe_instance_status' which is similar to if not the same as the python's get_all_instance_status.
I was then able to find this link:
http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/Client.html
This Client object is basically the under-the-covers query object that has access to all the api calls. This is now an easy task as the documentation describes that we can query and filter these results by passing an options {} to the describe_instance_status method:
>> ec2 = AWS::EC2::new(:aws_key_id => ENV['AWS_ACCESS_KEY_ID'], :aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'])
>> status = ec2.client.describe_instance_status({ "instance_ids" => ["i-xxxxxxx"] });
>> status
-> {:instance_status_set=>[{:events_set=>[{:code=>"instance-stop", :description=>"The instance is running on degraded hardware", :not_before=>2013-06-25 00:00:00 UTC}], :instance_id=>"i-xxxxxxxx",...
Hope this helps others seeking to do something similar.
Upvotes: 2