I am trying to set up Cloudwatch Alarms for an API Gateway. In this example I am trying to use the existing 4xx metric, but the Alarm never triggers even when the 4xx metric shows datapoints. I am struggling to find what I am doing wrong. At this point I just want to trigger the alarm as soon as any 4xx errors are raised, such as 404.
This is the terraform. I suspect the dimensions are wrong, but I am not sure. Thanks in advance!
resource "aws_cloudwatch_metric_alarm" "gateway_error_rate" {
alarm_name = "${local.workspace_name}-gateway-errors"
comparison_operator = "GreaterThanOrEqualToThreshold"
alarm_description = "Gateway error rate has exceeded threshold"
treat_missing_data = "missing"
metric_name = "4xx"
namespace = "AWS/ApiGateway"
period = 60
evaluation_periods = 1
threshold = 1
statistic = "Sum"
unit = "Count"
dimensions = {
ApiName = aws_apigatewayv2_api.my_gateway.name
Stage = aws_apigatewayv2_stage.default.name
}
}
I was not far off. The final terraform was changing dimensions from
ApiNametoApiIdand replacingunitwithdatapoints_to_alarm