If you run a service on the T2 tier of AWS, your machines have a specific compute budget. So, for example, you may want to delay certain CPU-intensive background tasks to a later time, throttling them by the CPUCreditBalance your machine currently has.
The current (averaged) CPUCreditBalance can be retrieved via CloudWatch, but I found the Java API rather unforgiving1 – it fails silently when certain elements like the unit (StandardUnit.Count) are missing from the API call. Here is a snippet that retrieves the last (average) CPUCreditBalance, as a starting point:
In any case, before using the Java API, I would always suggest to try out the request via the AWS CLI first; this is a complex API with many features. ↩