API Gateway detailed method metrics are disabled

Enable detailed CloudWatch metrics for API methods that need them.

Description

API Gateway publishes basic REST API and stage metrics. Enable detailed metrics to see values for a specific resource path and HTTP method.

Potential impact

A stage-wide metric can hide errors or latency affecting a single method.

Remediation

Set metrics_enabled = true for methods you need to investigate or alarm on. Detailed metrics incur additional charges. After a request to the method, check its resource and method dimensions in CloudWatch and configure any required alarms.

Examples

The example’s method_path selects one method on a single-segment resource. Both excerpts keep execution logging at INFO.

Before

hcl
resource "aws_api_gateway_method_settings" "example" {
  rest_api_id = aws_api_gateway_rest_api.test.id
  stage_name  = aws_api_gateway_stage.test.stage_name
  method_path = "${aws_api_gateway_resource.test.path_part}/${aws_api_gateway_method.test.http_method}"

  settings {
    metrics_enabled = false
    logging_level   = "INFO"
  }
}

After

hcl
resource "aws_api_gateway_method_settings" "example" {
  rest_api_id = aws_api_gateway_rest_api.test.id
  stage_name  = aws_api_gateway_stage.test.stage_name
  method_path = "${aws_api_gateway_resource.test.path_part}/${aws_api_gateway_method.test.http_method}"

  settings {
    metrics_enabled = true
    logging_level   = "INFO"
  }
}

References