Troubleshooting and Optimization

JSON access logs contain numeric status fields, with one event per request. A developer needs five-minute intervals containing at least 100 requests and more than 5% HTTP 5xx responses. Which CloudWatch Logs Insights query meets these requirements?

Show the answer

Correct answerB. stats count(*) as total, sum(status >= 500 and status < 600) as errors by bin(5m) | filter total >= 100 and 100.0 * errors / total > 5

AWhy not this: Grouping by status splits each interval into separate status groups instead of calculating its overall error percentage.

BWhy this is right: The aggregation retains all requests, counts 5xx responses separately, and applies both thresholds to each five-minute interval.

CWhy not this: Filtering first discards successful requests, so the count cannot represent total traffic or support the required error percentage.

DWhy not this: An error count greater than five is not the same as an error percentage greater than 5%.

Count all requests and conditionally sum 5xx responses within each time interval before applying the volume and percentage thresholds. Filtering to errors first removes successful requests from the denominator; grouping by status also prevents calculation of the overall interval error rate.