-
-
Save helresa/92274f4525acdd34f9351c81e681f103 to your computer and use it in GitHub Desktop.
AWS CloudWatch alarm rename script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import boto3 | |
| def rename_alarm(alarm_name, new_alarm_name): | |
| client = boto3.client('cloudwatch') | |
| alarm = client.describe_alarms(AlarmNames=[alarm_name]) | |
| if not alarm: | |
| raise Exception("Alarm '%s' not found" % alarm_name) | |
| alarm = alarm['MetricAlarms'][0] | |
| client.put_metric_alarm( | |
| AlarmName=new_alarm_name, | |
| ActionsEnabled=alarm['ActionsEnabled'], | |
| OKActions=alarm['OKActions'], | |
| AlarmActions=alarm['AlarmActions'], | |
| InsufficientDataActions=alarm['InsufficientDataActions'], | |
| MetricName=alarm['MetricName'], | |
| Namespace=alarm['Namespace'], | |
| Statistic=alarm['Statistic'], | |
| Dimensions=alarm['Dimensions'], | |
| Period=alarm['Period'], | |
| EvaluationPeriods=alarm['EvaluationPeriods'], | |
| Threshold=alarm['Threshold'], | |
| ComparisonOperator=alarm['ComparisonOperator'] | |
| ) | |
| # update actually creates a new alarm because the name has changed, so | |
| # we have to manually delete the old one | |
| client.delete_alarms(AlarmNames=[alarm_name]) | |
| 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