CloudWatch Logs Insights

0

How to convert a string value to a number in the CloudWatch Logs Insights query.

My Object

{
            "readonly": false,
            "value": "30",
            "key": "MeterValueSampleInterval"
        }

CloudWatch Logs Insights query

  • not working

    fields @timestamp, @message, @logStream, @log | parse @message/"MeterValueSampleInterval".*?"value\:" "(?<sample_interval>\d+)"/ | filter sample_interval == 30 | sort @timestamp desc | limit 1000

  • Try this

    parse @message/"MeterValueSampleInterval".*?"value" "(?<sample_interval>\d+)"
    

    or

    parse @message/"MeterValueSampleInterval".*?"value\\:" "(?<sample_interval>\d+)"
    
질문됨 한 달 전127회 조회
1개 답변
0

If you're logging a JSON object, CWL should parse it automatically out of the message for you (you'll see key, readonly and value show in the "Discovered Fields" panel on the right). You can just specify the fields in the fields keyword.

The documentation says that the comparison operators work on any datatype so there's no need to convert your string value to an int explicity (the error you're getting is because you're using a to_int() function which doesn't exist.

For example, I injected your sample message in to a log stream and I can find it with this query:

fields @timestamp, @message, value
| filter value = 30

Query demo

profile pictureAWS
전문가
James_S
답변함 한 달 전
profile picture
전문가
검토됨 한 달 전

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

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

질문 답변하기에 대한 가이드라인

관련 콘텐츠