in src/actions.py [0:0]
def create_alarm(AlarmName, MetricName, ComparisonOperator, Period, Threshold, Statistic, Namespace, Dimensions,
sns_topic_arn):
AlarmDescription = 'Alarm created by lambda function CloudWatchAutoAlarms'
try:
Period = convert_to_seconds(Period)
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 converting Period specified {} to seconds for Alarm {}!: {}'.format(Period, AlarmName, e))
Threshold = float(Threshold)
try:
cw_client = boto3_client('cloudwatch')
alarm = {
'AlarmName': AlarmName,
'AlarmDescription': AlarmDescription,
'MetricName': MetricName,
'Namespace': Namespace,
'Dimensions': Dimensions,
'Period': Period,
'EvaluationPeriods': 1,
'Threshold': Threshold,
'ComparisonOperator': ComparisonOperator,
'Statistic': Statistic
}
if sns_topic_arn is not None:
alarm['AlarmActions'] = [sns_topic_arn]
cw_client.put_metric_alarm(**alarm)
logger.info('Created alarm {}'.format(AlarmName))
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 creating alarm {}!: {}'.format(AlarmName, e))