내용으로 건너뛰기

CloudWatch Logs Subscription Filter Pattern to Match Multiple Words in Same Log Message

0

I’m using AWS CloudWatch Logs subscription filters to trigger a Lambda function based on certain log events. I want to trigger the Lambda only when both the words "fail" and "exception" appear in the same log message. I’ve tried using the filter pattern ?fail ?exception, but it only matches logs that contain one of the words, not both. Can someone explain how to write a CloudWatch Logs subscription filter that will match a log message containing both "fail" and "exception"? Is there a way to ensure that both words must appear in the same log message for the filter to trigger the Lambda function?

1개 답변
0
수락된 답변

Hello.

I think you can filter logs that include "fail" and "exception" using the filter pattern below.

fail exception

An example can be found in the documentation below.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html
a

전문가

답변함 일 년 전

전문가

검토됨 일 년 전

전문가

검토됨 일 년 전

  • Thanks for the answer. Maybe you know how to make the word case-insensitive?

  • As of January 2025, I don't think there is a syntax for searching without considering uppercase and lowercase letters in the subscription filter. If you use "?", it becomes an OR condition, but in that case, you will not be able to use an AND condition, so your request will not be met. a

    If the log is space-delimited, I think you can use a filter pattern like the one below. However, I think that even in this case you need to format it in such a way that it includes all the pattern words to make it case sensitive. For example, it is not possible to distinguish between "Fail", "fail", and "FAIL", so these must be included in the filter pattern.

    [(mes="*fail*" && mes="*exception*" || mes="*FAIL*" && mes="*EXCEPTION*")]
    

    a

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.