How do I avoid throttling when I call PutMetricData in the CloudWatch API?
Last updated: 2020-11-06
I'm receiving the error "400 ThrottlingException" for PutMetricData API calls in Amazon CloudWatch. How can I fix this?
When you receive the error "400 ThrottlingException" for PutMetricData API calls in CloudWatch, you also receive the following detailed response:
<ErrorResponse xmlns="http://monitoring.amazonaws.com/doc/2010-08-01/"> <Error> <Type>Sender</Type> <Code>Throttling</Code> <Message>Rate exceeded</Message> </Error> <RequestId>2f85f68d-980b-11e7-a296-21716fd2d2e3</RequestId> </ErrorResponse>
CloudWatch requests are throttled for each Amazon Web Services (AWS) account on a per-Region basis to help service performance. For current PutMetricData API request quotas, see CloudWatch service quotas.
Note: All calls to the PutMetricData API in an AWS Region count towards the maximum allowed request rate. This number includes calls from any custom or third-party application, such as calls from the CloudWatch Agent, the AWS Command Line Interface (AWS CLI), or the AWS Management Console.
It's a best practice to use the following methods to reduce your call rate and avoid API throttling:
- Distribute your API calls evenly over time rather than making several API calls in a short time span. If you require data to be available with a one-minute resolution, you have an entire minute to emit that metric. Use jitter (randomized delay) to send data points at various times.
- Combine as many metrics as possible into a single API call. For example, a single PutMetricData call can include 20 metrics and 150 data points. You can also use pre-aggregated data sets, such as StatisticSet, to publish aggregated data points, thus reducing the number of PutMetricData calls per second.
- Retry your call with exponential backoff and jitter.