in src/actions.py [0:0]
def delete_alarms(name):
try:
AlarmNamePrefix = "AutoAlarm-{}".format(name)
cw_client = boto3_client('cloudwatch')
logger.info('calling describe alarms with prefix {}'.format(AlarmNamePrefix))
response = cw_client.describe_alarms(
AlarmNamePrefix=AlarmNamePrefix,
)
alarm_list = []
logger.info('Response from describe_alarms(): {}'.format(response))
if 'MetricAlarms' in response:
for alarm in response['MetricAlarms']:
alarm_name = alarm['AlarmName']
alarm_list.append(alarm_name)
logger.info('deleting {} for {}'.format(alarm_list, name))
response = cw_client.delete_alarms(
AlarmNames=alarm_list
)
return True
except Exception as e:
# If any other exceptions which we didn't expect are raised
# then fail and log the exception message.
logger.error(
'Error deleting alarms for {}!: {}'.format(name, e))