Filter Lambda Invocation error based on the consumer

0

We have a lambda that is invoked by different consumer. Is it possible to filter out invocation error based on a specific consumer? We would like to create an alarm based on this use case.

Qayyuum
已提問 2 個月前檢視次數 375 次
2 個答案
2

Can you give an example of logs you have?

To see the logs you can check out Logs Insights and create a query like

fields @timestamp, @message, @logStream, @log
| filter userId like "123"

To create an alarm for these errors there are probably two solutions. Remember, that alarms are always based on metrics. That means you need to get somehow a metric for all errors by user ID.

1. Create a Custom Metric

You could create a custom metric within your code (e.g. with the EMF format) and add the user ID as a dimension. Then you can create an alarm on this metric. Since the dimension is the user ID you would need to create a metric insight query for that that this is dynamic.

2. Create Metric Filter

You could create a metric filter. This creates a new metric based on your logs. You need to define a filter based on your logs, for example:

{ $.consumerID = "specificConsumerID" && $.error = true }

This could be a bit cumbersome if you need to do this for all new users so I don't think this is really suitable.

But I think you can also just create a filter on the error $.error = true and add the consumerID as a dimension.


I hope that helps, need to implement it myself to check if I missed something.

profile picture
已回答 2 個月前
0

Hello, you can accomplish this by setting up CloudWatch Logs subscriptions targeting a Lambda function ( and in the lambda you can create ur desired alarm)

Paul
已回答 2 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南