Can you tell which cloudwatch log subscription fire off a lambda? - aws-lambda

I have 2 cloudwatch log subscriptions from the same log, that both pointing to the same lambda function.
Is there anyway to tell which subscription fired off the lambda from the logs or event? i dont see anything in the destination function logs except for the line(s) from the log that caused it to run.

Related

AWS Cloudwatch Subscription Filter and Dead Letter Queue for Lambda

I am using CloudWatch log subscription filters to get logs from a specific log group and send them to a Lambda function, which after processing will send the results to another service. I wonder if there's any possibility to send failed events by Lambda to a Dead Letter Queue, noting that in the above settings, we have no SNS/SQS setup to trigger the Lambda.
Destinations gives you the ability to handle the Failure of function
invocations along with their Success. When a function invocation
fails, such as when retries are exhausted or the event age has been
exceeded (hitting its TTL), Destinations routes the record to the
destination resource for every failed invocation for further
investigation or processing.
To configure destination in Lambda function, Kindly refer

How to List Lambda Triggers associated with a SQS Queue

A few overview points:
I can go into the Lambda console, click a Lambda function, click Configuration then Triggers, and see that there is an SQS Queue added as a trigger to this Lambda function.
I can then go into the SQS console, click on that corresponding Queue and then click on the Lambda Triggers tab. That tab will show the Lambda function that was previously mentioned.
I've had an exceedingly difficult time returning a list of triggers associated with a Lambda function through the SDK so I'm wonder if it is possible to use the SQS SDK to query an SQS Queue and have it return all Lambda Triggers associated with that Queue?

AWS Event Bridge Lambda invocation

I have configured a lambda function as EventBridge rule target and I have configured a Dead Letter Queue on the EventBridge rule to capture exceptions.
Now, if the lambda function fails, Event Bridge does not recognize that failure as an error.
Since the EventBridge invocation to the Lambda is asynchronous, for EventBridge it is enough to reach the lambda to consider the event as successfull,but in this way I am not able to track and retry events once lambda fails.
Anyone know a way to make the EventBridge to the Lamdba request synchronous or another way to be able to Retry the events if the Lambda code fails after the invocation?
one option is to make the SQS to be rule target and use SQS event to trigger the lambda. when failure occurs, the lambda won't flag the event done so as to keep the event in the SQS. retry will auto happen after a configured period (SQS configuration). also you can configure dead letter queue after the retention time expires
EventBridge guarantees the delivery of the event to the lambda function but is not aware of what happens post that. It's lambda invocation vs lambda execution. Eventbridge successfully delivered the message to the lambda service, so it's a successful invocation.
For Lambda, EventBridge calls invokeAsync API. So, if this API sends a success response, EventBridge will assume the delivery was successful. Any failures within Lambda from async to sync is not visible to EventBridge. We should configure retries and create DLQs in our Lambda functions to make sure the events are not lost in case the Lambda function fails to execute. We could in fact configure the same DLQ used by the EventBridge to be used by the Lambda as well so that all eventual failures land in a single place.
AWS has a dedicated documentation page for this, which states the following for asynchronous invocation:
Lambda retries function errors twice. If the function doesn't have enough capacity to handle all incoming requests, events might wait in the queue for hours or days to be sent to the function. You can configure a dead-letter queue on the function to capture events that weren't successfully processed. For more information, see Asynchronous invocation.
So that means that as long as your Lambda functions handler function does return an error, the AWS Lambda service should retry to run your Lambda again.
Therefore, you might not need EventBridge to retry your event.
See: Error handling and automatic retries in AWS Lambda

DynamoDB trigger sometimes giving an error

I have a lambda trigger on a dynamoDb table event.
Sometimes the trigger is running fine, but sometimes Function call Failed error is thrown.
The lambda memory is set to 1024MB and timeout to 05mins.
The problem is that when the function call failed error comes, no logs are logged on cloudWatch, hence I am not able to debug or identify why the error is coming.
Any insights on how to identify the issue?
I recommend following the example in this article, New AWS Lambda controls for stream processing and asynchronous invocations, to set up some error handling. It will give you some visibility to what is going on.
Basically, use Lambda Destinations for failures.

redirect aws lambda logs to a particular log group in cloudwatch

I have multiple lambda's. Is there a way to direct the logs from all these lambda to a specific cloud watch log group instead of each going to their own.
Turns out the other question is similar and looks like there is no way to currently aggregate logs from different lambda services.
I ended up creating an SQS FIFO queue. Send log messages to the queue from lambda and created a Log Lambda that will basically print all messages from the sqs queue.
When I want to view the logs I go the cloudwatch logs for the Log Lambda which have everything ordered.

Resources