Hi,
I have CloudWatch alerts configured for ELBs. Unfortunately alerts name have random ELBs names inherited which looks ugly:
resource "aws_cloudwatch_metric_alarm" "elb-5xx-backend-anomaly" {
count = length(var.monitored-elb-ids)
alarm_name = join("", ["ELB 5xx BACKEND errors high - ", var.monitored-elb-ids[count.index]])
comparison_operator = "LessThanLowerOrGreaterThanUpperThreshold"
evaluation_periods = "1"
threshold_metric_id = "e1"
alarm_description = "description"
treat_missing_data = "notBreaching"
alarm_actions = [element(var.sns-topics.*.topic-id, 1)]
ok_actions = [element(var.sns-topics.*.topic-id, 1)]
metric_query {
id = "e1"
expression = "ANOMALY_DETECTION_BAND(m1, 1)"
label = "HTTPCode_Backend_5XX (expected)"
return_data = "true"
}
metric_query {
id = "m1"
return_data = "true"
metric {
metric_name = "HTTPCode_Backend_5XX"
namespace = "AWS/ELB"
period = "60"
stat = "Sum"
unit = "Count"
dimensions = {
LoadBalancerName = var.monitored-elb-ids[count.index]
}
}
}
}
so that creates an alert like:
module.cloudwatch-load-balancer-alerts.aws_cloudwatch_metric_alarm.elb-5xx-anomaly[0]: Creating...
module.cloudwatch-load-balancer-alerts.aws_cloudwatch_metric_alarm.elb-5xx-anomaly[0]: Creation complete after 0s [id=ELB 5xx errors high - a2e088xxxxxxxxxxxxxxxxxxxxxxxxxxxx]
I found Cloudposse label module but that looks massively over complicated and seems that it needs creating module for each load balancer. Is there any easier way of doing that?