Skip to content

Instantly share code, notes, and snippets.

@duggan
Created April 3, 2012 02:50
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 duggan/2288942 to your computer and use it in GitHub Desktop.
Save duggan/2288942 to your computer and use it in GitHub Desktop.
Print degraded instances
import sys
from boto.ec2.connection import EC2Connection
from boto.exception import BotoServerError
AMZN_ACCESS_KEY = ""
AMZN_SECRET_KEY = ""
maintenance_instances = []
""" Get EC2 connection """
try:
ec2 = EC2Connection(AMZN_ACCESS_KEY, AMZN_SECRET_KEY)
""" Get list of instances which require maintenance """
statuses = ec2.get_all_instance_status()
except BotoServerError:
print "Failed to communicate with EC2 (%s)" % BotoServerError
for status in statuses:
if status.events:
event = status.events[0]
if "[Completed]" not in event.description:
maintenance_instances.append({"Event":event.code,
"Description":event.description, "Instance ID":status.id})
print maintenance_instances
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment