Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Log Insights query with string contains

how to I query with contains string in AWS Log insights

fields @timestamp, @message filter @message = "user not found" | sort @timestamp desc | limit 20  fields @timestamp, @message filter @message strcontains("User not found") | sort @timestamp desc | limit 20 
like image 502
kumar Avatar asked May 25 '20 04:05

kumar


People also ask

How do I query log insights in CloudWatch?

Use the sort command to display log events in ascending ( asc ) or descending ( desc ) order. Use the limit command to specify the number of log events that you want your query to return. Use the parse command to extract data from a log field and create an ephemeral field that you can process in your query.

How do I filter messages in CloudWatch logs?

For information about how to create a log group, see Create a log group in CloudWatch Logs in the Amazon CloudWatch Logs User Guide. Choose Actions, and then choose Create metric filter. For Filter Pattern, enter { $. latency = * } , and then choose Next.


2 Answers

This should work fine

fields @timestamp, @message | filter @message like /user not found/ | sort @timestamp desc | limit 20 
like image 173
Parichit Choubisa Avatar answered Sep 27 '22 00:09

Parichit Choubisa


I think you need to select them as fields and then filter on their value. e.g:

fields @timestamp, @message, strcontains(@message, "user not found") AS unf | filter unf=1 | sort @timestamp desc | limit 20 

Or use regex

fields @timestamp, @message | filter @message like /User\snot\sfound/ | ... 

(haven't tested them)

like image 30
Carlos Avatar answered Sep 25 '22 00:09

Carlos