I receive the error "400 ThrottlingException" for PutMetricData API calls in Amazon CloudWatch.
Short description
When you receive the error "400 ThrottlingException" for PutMetricData API calls in CloudWatch, you also receive the following message:
<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>
To help service performance, CloudWatch throttles requests for each AWS account based on the AWS Region. For current PutMetricData API request quotas, see CloudWatch service quotas.
Note: All calls to the PutMetricData API in a Region count towards the maximum allowed request rate. This number includes calls from any custom or third-party application. Examples of such applications include the CloudWatch Agent, the AWS Command Line Interface (AWS CLI), and the AWS Management Console.
Resolution
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 period. If you require data to be available with a 1-minute resolution, then 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 1,000 metrics and 150 data points. You can also use pre-aggregated data sets, such as StatisticSet, to publish aggregated data points. This reduces the number of PutMetricData calls per second.
- Retry your call with exponential backoff and jitter.
Related information
CloudWatch API reference