Search code examples
amazon-cloudwatchaws-cloudwatch-log-insights

Is there a way to truncate a field value in CloudWatch?


Suppose I have a simple Insights query like so

fields @timestamp, @message

Is there a way to truncate the @message field. For example, say I only want to skip the 1st 50 characters.

I know I can use the parse function but is there a simpler way, an substring equivalent that I can use in the fields line perhaps


Solution

  • There is a substr function:

    Returns a substring from the index specified by the number argument to the end of the string. If the function has a second number argument, it contains the length of the substring to be retrieved. For example, substr("xyZfooxyZ",3, 3) returns "foo".

    https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html