A developer wants to create an Amazon CloudWatch metric filter to count occurrences of the term 'AccessDenied' in a plain text log group. The developer attempts to use the following CloudWatch Logs Insights query syntax as the metric filter pattern:
`fields @message | filter @message like /AccessDenied/`
However, the metric is not being incremented even when 'AccessDenied' appears in the logs.
Which of the following is the correct explanation and resolution for this issue?
- Metric filters do not support CloudWatch Logs Insights query syntax. The filter pattern should be changed to the literal string 'AccessDenied'.Answer
- BMetric filters can only parse JSON-formatted logs. The developer must convert the application's logging library output to JSON format to use metric filters.
- CThe metric filter pattern is correct, but the metric does not increment because the IAM execution role of the application generating the logs lacks the 'logs:StartQuery' permission.
- DThe metric filter failed to process the logs because the log group's processing duration exceeded the default execution timeout of the underlying log parser.
Answer
Metric filters do not support CloudWatch Logs Insights query syntax. The filter pattern should be changed to the literal string 'AccessDenied'.
The correct answer is correct because CloudWatch Logs metric filters and CloudWatch Logs Insights are two distinct features with different syntaxes. Metric filters scan logs during ingestion using basic string matching patterns or JSON properties, and they do not understand the pipe-separated query syntax of Logs Insights. By changing the pattern to the simple string 'AccessDenied', the filter will correctly match any log line containing that term.
Step-by-Step Solution
Key Concept
CloudWatch Logs metric filters use a simple term-matching or JSON-matching syntax and do not support CloudWatch Logs Insights query syntax.