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.
Thanks
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.See http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/CloudWatch/AlarmHistoryItemCollection.html
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.