Why is there a difference between the Count value and the usage plan usage value in API Gateway?

Why is there a difference between the Count value and the usage plan usage value in API Gateway?

Clock Icon2025.05.08

日本語版はこちら

The issue

During the development stage, I am measuring the number of API Gateway invocations.
Why is there a difference between the Count metric that can be seen in the CloudWatch console and the usage plan usage value that can be seen in the API Gateway usage plan regarding the number of API Gateway invocations?

The solution

In API Gateway's usage plans, quota consumption is counted when requests with valid API keys are successfully accepted.
Quota from the usage plan is consumed in the same way as when a normal response is received from the backend, even if the request is received normally within the quota limit and then an error is responded from the API backend such as Lambda.

API GatewayのAPIキーと使用量プランについて調べてみた | DevelopersIO

API Gatewayから呼び出したLambda関数がエラーを返した場合もAPIキーと使用量プランのアクセス回数には計上されますので注意してください。

Gateway response error responses, such as when requests are received for non-existent resources or methods on the API stage, are not counted towards quota consumption.

On the other hand, CloudWatch's Count metric is recorded even when requests occur for resources or methods that do not require an API key, or when error responses occur that do not involve quota consumption from the usage plan due to gateway responses.

Therefore, even when targeting the same stage, the values of CloudWatch's Count metric and API Gateway's usage plan may not match.

Note

The application of quotas by usage plans operates on a best-effort basis.
Therefore, please note that there may be a slight difference between the number of quotas consumed in the usage plan and the actual number of requests processed.

Usage plans and API keys for REST APIs in API Gateway - Amazon API Gateway

Usage plan throttling and quotas are not hard limits, and are applied on a best-effort basis. In some cases, clients can exceed the quotas that you set. Don’t rely on usage plan quotas or throttling to control costs or block access to an API. Consider using AWS Budgets to monitor costs and AWS WAF to manage API requests.

References

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.