Error while creating an cloudwatchMetricFilter with Cloudformation

0

Hi together, I'm trying to create an Cloudwatch Metric Filter with Cloudformation:

myCWMetric:
    Type: AWS::Logs::MetricFilter
    Properties:
      LogGroupName: /aws/lambda/mybackend-list
      FilterPattern: "[...,uri=%contacts%, duration,]"
      MetricTransformations:
        - MetricValue: "$.duration"
          MetricNamespace: mybackend-list/apiDurations
          MetricName: ContactMediaDuration
          Unit: Milliseconds

The ErrorMesage which is Cloudformation is throwing is the following:

Resource handler returned message: "Invalid request provided: AWS::Logs::MetricFilter. Invalid metric transformation: metric value $.duration must be a valid number

anyone have an idea how to solve this issue?

Thx :-) Oliver

Oliver
已提问 9 个月前455 查看次数
1 回答
1
已接受的回答

Hello.

The error message suggests that the $.duration is not being interpreted as a valid number, which might be happening because of the filter pattern or a mismatch with the actual log event format.

Ensure that the duration placeholder correctly matches the actual logs. For example, if your log line is something like:

some-text uri=/contacts/123 duration=456

Then your filter pattern might look something like:

FilterPattern: "... uri=%contacts% duration=$[duration]"

Regards, Andrii

profile picture
专家
已回答 9 个月前
profile picture
专家
已审核 2 个月前
  • Hi Andrii, Thanks for your answer. Finaly I found the issue:

    The Attribute MetricValue must be $duration instead of $.duration. The AWS Documentation was in this case not so helpfull, because this case is not handled there.

    Regards Oliver

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则