Listing pending Amazon EC2 events using Boto and Python

Posted by on Dec 8, 2011 in Amazon Web Services, Blog, Operations

Recently Amazon added an API call enabling the querying of the status of an instance.  Some new instance events were introduced, including the instance-reboot and the (yet to be seen) system-reboot and retirement.  Shortly after this call was introduced Amazon sent email to many accounts listing pending instance-reboots for many instances.  I do not know the reason for the sudden in-rush of required instance reboots; a Xen security hole?  pending maintenance that was delayed until the API call was available?  I do suspect the retirement event was added due to the rumored retirement of one of the availability zones in us-east-1 (three year reserved instances are no longer a purchase option for that one zone.), or perhaps Amazon just has older hardware they want to retire for power or performance reasons.

The team that maintains the Boto library quickly added support for the new API call and Boto author Mitch Garnaat posted a quick example of how to use it.

At 42 Lines we are fairly heavy users of the ec2 tagging feature.  I noticed that the AWS Console does not allow one to display arbitrary tags in the scheduled events view, so I put together a Python script that does.  The code is here.  Here’s an example of the output (anonymized):

jbrowne@foo:~$ ~/instance_events -H ID,Code,NotBefore,NotAfter,T:hostname -S NotBefore
ID            Code              NotBefore                NotAfter                 T:hostname
i-695cf65b    instance-reboot   2011-12-13T04:00:00.000Z 2011-12-13T10:00:00.000Z
i-9a1d5fba    instance-reboot   2011-12-17T04:00:00.000Z 2011-12-17T10:00:00.000Z
i-2869f0ee    instance-reboot   2011-12-17T04:00:00.000Z 2011-12-17T10:00:00.000Z
i-5bba755f    instance-reboot   2011-12-17T04:00:00.000Z 2011-12-17T10:00:00.000Z
i-bc22c063    instance-reboot   2011-12-17T04:00:00.000Z 2011-12-17T10:00:00.000Z
i-57fab14f    instance-reboot   2011-12-17T04:00:00.000Z 2011-12-17T10:00:00.000Z
i-37dd9809    instance-reboot   2011-12-20T04:00:00.000Z 2011-12-20T10:00:00.000Z

Next steps could include wrapping the code to use it as a NAGIOS/Icinga plugin or outputting RSS for use with our IRC LogBot to give us a heads up when new events arise.

Updated (12/12/2011): It turns out that AWS inserts “[Completed]” into the event description when the event has completed rather than just removing the event from the list.  I’ve updated my script to better represent completed events.