How do I avoid throttling when I call PutMetricData in the CloudWatch API?
Last updated: 2019-08-12
I'm receiving the error 400 ThrottlingException for PutMetricData API calls in Amazon CloudWatch with 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>
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.
If you still require a higher limit, you can request a limit increase. Increasing the rate limit can have a high financial impact on your AWS bill. Be sure to try the previously described methods to avoid API throttling before requesting a rate limit increase. If you request a limit increase, be sure to provide the following information:
- The reason why it is difficult for your application to follow best practices.
- The approximate date/time range (including your time zone) when you made PutMetricData calls at the highest rate and experienced throttling.