cloudwatch 指标过滤器模式与 json 日志不匹配

cloudwatch metric Filter Pattern doesn't match with the json logs

我正在尝试为我的服务配置一个自定义指标来监控服务的正常运行时间,我正在尝试获取状态代码的值并在该值为 4* 和 5* 时发出警报我是尝试使用 json 过滤器模式匹配 statusCode 但无法使其正确

 {
        "res": {
            "statusCode": 500
        },
        "req": {
            "url": "",
            "headers": {
                "host": "",
                "connection": "close",
                "user-agent": "",
                "accept-encoding": "gzip, compressed"
            },
            "method": "GET",
            "httpVersion": "1.1",
            "originalUrl": "",
            "query": {}
        },
        "responseTime": 1,
        "requestId": "",
        "level": "info",
        "message": "",
        "timestamp": ""
    }

我的过滤模式是 这两个我都试过了,但是 none 成功了 {$.res.statusCode = 500}

{($.res.statusCode = 2*)||($.res.statusCode = 5*)}

我正在努力关注https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html

似乎是 json 的问题,当我们复制粘贴时 json 不起作用, 如果从 Log Data to Test 下拉列表中选择,过滤器在这种情况下对我有用。

对我有用的答案是 AWS Cloudwatch Json Metric Filter Pattern

引用,

When using the Test Metric Filter feature in the AWS Console, each log event has to be in a separate line. You can still run the same test, but you have to remove all new lines from the sample data.