2013-10-21 70 views
2

我正在嘗試爲可維護性組織大量的CloudWatch鬧鐘,並且Web控制檯在編輯時爲其命名。是否有另一種更新CloudWatch警報名稱的方法(最好是可編寫腳本的)?我更喜歡不需要任何編程而不是簡單的可執行腳本的解決方案。重命名Amazon CloudWatch鬧鐘

回答

1

不幸的是,它看起來像這是不可能的。

2

下面是我們用來暫時做到這一點的腳本:

import sys 
import boto 


def rename_alarm(alarm_name, new_alarm_name): 
    conn = boto.connect_cloudwatch() 

    def get_alarm(): 
     alarms = conn.describe_alarms(alarm_names=[alarm_name]) 
     if not alarms: 
      raise Exception("Alarm '%s' not found" % alarm_name) 
     return alarms[0] 

    alarm = get_alarm() 

    # work around boto comparison serialization issue 
    # https://github.com/boto/boto/issues/1311 
    alarm.comparison = alarm._cmp_map.get(alarm.comparison) 

    alarm.name = new_alarm_name 
    conn.update_alarm(alarm) 

    # update actually creates a new alarm because the name has changed, so 
    # we have to manually delete the old one 
    get_alarm().delete() 

if __name__ == '__main__': 
    alarm_name, new_alarm_name = sys.argv[1:3] 

    rename_alarm(alarm_name, new_alarm_name) 

它假定你要麼就與角色的EC2實例,讓這一點,或者你有一個〜/。博客文件與您的憑據。很容易手動添加你的。