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
asked a month ago365 views
2 Answers
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
answered a month ago
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
answered a month 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