I am using Python Boto to launch new server in AWS VPC, I have SNS topic setup and I plan to get notified when my new server's System reachability check and Instance reachability check fails. For achieving this I am getting list of metrics(this is all a part of creating a new alarm as a part of server provision script):

cw_conn.list_metrics(dimensions={'InstanceId':instance_id}, metric_name=StatusCheckFailed)[0]

Problem is that when a instance starts all the metrics are not available immediately and I get IndexError: 'list index out of range' error.

I would really appreciate if anyone who has a solution to this problem can guide me or share a work around this issue.



Instead of assuming that the metric exists, check for it first. If it doesn't exist then check the instance launch date. If it is recent then ignore the fact that the metric does not exist (yet); otherwise signal something is wrong.


The only way I know of is to create the alarm with with_start_date for some time in the future, like an hour or a day, in order to give the instances a chance to return OK at least once.

def with_start_date date
  date = date.iso8601 if date.respond_to?(:iso8601)
  filter(:start_date, date)

See http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/CloudWatch/AlarmHistoryItemCollection.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.