DVA-C02 Question 335
Single answerYou are a developer tasked with analyzing application logs stored in Amazon CloudWatch Logs. You need to identify the average response time for a specific API endpoint where the log entries include a field called responseTime and a field called endpoint. Which of the following CloudWatch Logs Insights query snippets would achieve your goal?
- A
fields responseTime | stats avg(responseTime) by endpoint | filter endpoint = '/api/v1/resource'
- B
stats avg(responseTime) by endpoint | filter endpoint = '/api/v1/resource'
- C
fields endpoint, responseTime | filter endpoint = '/api/v1/resource' | stats avg(responseTime)
- D
filter endpoint = '/api/v1/resource' | stats avg(responseTime) | fields responseTime
Show answer and explanation
Correct answer: C
Explanation
In Amazon CloudWatch Logs Insights, the correct order of operations is crucial for accurate results. You should first extract the necessary fields, then apply any filters to reduce the dataset, and finally perform aggregation using commands like stats. Option 3 adheres to this logical flow, making it the correct answer.
- A. Incorrect.
This query tries to use the
fieldscommand to extractresponseTimeand then aggregate withstats, but it incorrectly places thefilterafter the aggregation which would result in incorrect filtering. - B. Incorrect.
This query attempts to aggregate using
stats avg(responseTime)without first extracting theresponseTimefield or applying the filter before the aggregation, making it invalid. - C. Correct.
This is the correct query because it first selects the necessary fields (
endpointandresponseTime), applies the filter to narrow down to the specific endpoint (/api/v1/resource), and then calculates the average response time using thestatscommand. - D. Incorrect.
This query places the
filteroperation after the aggregation (stats), which is not valid in CloudWatch Logs Insights syntax.