Api Gateway does not generate metrics in CloudWatch

0

We created some API Gateway resources of type AWS::Serverless::Api with CloudFormation, where all have the same value of ApiName and with the MethodSetting parameter we enable the metrics for all paths that have the different API Gateway in the same AWS account. After creating the API Gateway resource in the Amazon console and after a few days of running requests on the API, we only see the metrics 4XXError, 5XXError, Count, Latencies and Integration Latencies corresponding to a single API Gateway, the rest of the API Gateway did not generate any metrics in CloudWatch. At this point, we decided to assign a different API name to each API Gateway. However, these API Gateways still do not generate metrics in CloudWatch. Any idea about the problem we are having?

1 Answer
0
Accepted Answer

API Gateway only enables Metrics when the 'MetricsEnabled' value is set to true for 'StageDescription' [1] on the API Gateway Stage level. If this value is diabled API Gateway will not send these metrics unless you have explicitly enabled detailed CloudWatch metrics [2] on the stage level. The 'MethodSetting' only works when the stage level metrics has been enabled, method level metrics allows you to be able to filter these metrics on cloudwatch. The 'MethodSettings' property of the Amazon API Gateway Deployment StageDescription property type contains a list of MethodSetting property types [3].

Enable stage metrics on the cloudformation stack and test if this works, eg:
StageDescription:
      Description: API details
      LoggingLevel: INFO
      MetricsEnabled: True
      MethodSettings:
        - ResourcePath: "/test"
          HttpMethod: "POST"
          LoggingLevel: INFO
          MetricsEnabled: True

References:

  1. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-deployment-stagedescription.html
  2. https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-metrics-and-dimensions.html
  3. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-deployment-methodsetting.html
AWS
answered 9 months ago
profile picture
EXPERT
reviewed 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions