What is CloudWatch `get_metric_statistics` vs `get_metric_data`?
AdvancedConceptboto3 & AWS automation
Answer
get_metric_statistics: one metric per call, simple, returnsDatapointsunordered, limited to 1,440 datapoints per call.get_metric_data: up to 500 metric queries per call, supports metric math and Metrics Insights, returns ordered values with pagination. Far cheaper and faster for scanning a fleet.
For an "idle instance" check across 2,000 instances, batching CPU queries in get_metric_data turns 2,000 calls into 4. Remember that CPUUtilization exists only for running instances, and the default period is 5 minutes (1 minute with detailed monitoring).
More on boto3 & AWS automation
What is the difference between a boto3 Session, client and resource?BeginnerHow does boto3 find credentials?BeginnerHow does boto3 decide the region, and what is the gotcha with `AWS_REGION`?AdvancedWhy do you need paginators, and how do you use them?BeginnerWhat is JMESPath `search()` on paginators?AdvancedHow do you handle errors from boto3?Beginner