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

1 Answer
1
Accepted Answer

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
EXPERT
answered 8 months ago
profile picture
EXPERT
reviewed 16 days ago
  • 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

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions