Capturing Lambda errors using Metric Filters

0

I have a lambda that throws custom error messages. I want to capture these error messages and trigger a cloudwatch alarm.

Using log groups, I have created a metric filter to capture ‘Error_1’ message.

I have created a cloud watch alarm for this metric_filter.

Next, I put an error message in the log using something like: aws logs put-log-events --log-group-name testgroup --log-stream-name teststream1 --log-events timestamp=1587488538,message=Error_1

I can see the error message in the log stream. However, metric filter does not show any error being logged.

Any idea, how I can trigger metric filter to capture error messages?

Do I need to include something under dimensions for metric filter or Cloudwatch alarm?

  • Is the problem that the metric is not triggering, or that you want the metric to capture the contents of your log?
    If the former, can you share the metric filter your re using?

QAS
asked 5 months ago244 views
1 Answer
0

Hi, from what you describe it sounds like you have created a metric filter before sending any logs to CloudWatch, and when you start sending logs, you fail to see the metric filter detecting your logs.

It sounds as if your metric filter may not be properly defined. It is usually best when you start using Metric Filters for the first time to send a few sample logs first to CloudWatch, and then create the metric filter from the wizard, as you can test your filter from the first step on the wizard on the existing data that you have sent to your log group. That would comfort you and eliminate possible error causes if you can prove from that step that your filter actually picks the logs you expect. Dimensions are optional and only apply to JSON or delimited filter patterns, the option won't be available on plain text filters like the one you seem to be willing to define.

The best would be to work backward from what you need: consider how you want to log messages (do you use JSON, a structure, plain text and what info are you adding, e.g. error message, call stack, pointer to location in the code…) and what metric you are willing to extract (just a count of occurrences or the sum or other stat on one of the logged values), then create a few sample messages with the structure and info you want to log, and work out your filter syntax from there.

profile pictureAWS
Jsc
answered 5 months ago

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