I'm trying to setup and alarm in Cloudwatch using terraform. My alarm basically needs to check if there is more than 5% of 5xx errors in the gateway during 2 periods of 1 minute.
I've tried the following code but it's not working:
resource "aws_cloudwatch_metric_alarm" "gateway_error_rate" {
alarm_name = "gateway-errors"
comparison_operator = "GreaterThanOrEqualToThreshold"
alarm_description = "Gateway error rate has exceeded 5%"
treat_missing_data = "notBreaching"
metric_name = "5XXError"
namespace = "AWS/ApiGateway"
period = 60
evaluation_periods = 2
threshold = 5
statistic = "Average"
unit = "Percent"
dimensions = {
ApiName = "my-api"
Stage = "dev"
}
}
Even thee alert is deployed, the data is not displayed. Doing some tests I've noticed that apparently the unit "percent" is not accepted for this alarm.
Does anyone have an example in terraform or cloudformation on how to configure this type of alarms?