我一直在撞牆試圖做這項工作。 我正在嘗試使用python/boto創建恢復失敗的ec2實例的cloutwatch警報。 我在獲取ec2:RecoverInstance操作時很困難。我懷疑我的話題沒有正確設置。Boto/Cloudwatch恢復實例鬧鐘
topics = sns_conn.get_all_topics()
topic = topics[u'ListTopicsResponse']['ListTopicsResult']['Topics'][0]['TopicArn']
# arn:aws:sns:us-east-1:*********:CloudWatch
status_check_failed_alarm = boto.ec2.cloudwatch.alarm.MetricAlarm(
connection=cw_conn,
name=_INSTANCE_NAME + "RECOVERY-High-Status-Check-Failed-Any",
metric='StatusCheckFailed',
namespace='AWS/EC2',
statistic='Average',
comparison='>=',
description='status check for %s %s' % (_INSTANCE, _INSTANCE_NAME),
threshold=1.0,
period=60,
evaluation_periods=5,
dimensions={'InstanceId': _INSTANCE},
# alarm_actions = [topic],
ok_actions=[topic],
insufficient_data_actions=[topic])
# status_check_failed_alarm.add_alarm_action('arn:aws:sns:us-east-1:<acct#>:ec2:recover')
# status_check_failed_alarm.add_alarm_action('arn:aws:sns:us-east-1:<acct#>:ec2:RecoverInstances')
status_check_failed_alarm.add_alarm_action('ec2:RecoverInstances')
cw_conn.put_metric_alarm(status_check_failed_alarm)
任何建議將不勝感激。
謝謝。
--Mike
在哪裏定義了「topic」。您可以查詢所有主題,例如'sns = connect_to_region(...); topics = sns.get_all_topics()'或者只需在AWS管理控制檯中查找SNS ARN。它應該看起來像'arn:aws:sns:::'。 –
AChampion
嗨AChampion - 我已更新我的代碼以顯示主題 - 檢索部分。 –