Skip to content

Instantly share code, notes, and snippets.

@parker-jana
Created December 15, 2014 16:19
Show Gist options
  • Save parker-jana/0d303c7d6e623edbd443 to your computer and use it in GitHub Desktop.
Save parker-jana/0d303c7d6e623edbd443 to your computer and use it in GitHub Desktop.
This is a quick script to rename an alarm in aws, as the console doesn't allow it yet.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment