I'm trying to organize a large number of CloudWatch alarms for maintainability, and the web console grays out the name field on an edit. Is there another method (preferably something scriptable) for updating the name of CloudWatch alarms? I would prefer a solution that does not require any programming beyond simple executable scripts.

有帮助吗?

解决方案 2

Unfortunately it looks like this is not currently possible.

其他提示

Here's a script we use to do this for the time being:

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)

It assumes you're either on an ec2 instance with a role that allows this, or you've got a ~/.boto file with your credentials. It's easy enough to manually add yours.

I looked around for the same solution but it seems neither console nor cloudwatch API provides that feature.

Note:

But we can copy the existing alram with the same parameter and can save on new name

.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top