Search code examples
aws-lambdaamazon-sqs

Capturing errors when Lambda bound to SQS queue


Is there any way to capture Lambda errors in the above situation ?

Messages passed to a Lambda destination contain the error trace, but messages passed to a dead letter queue appear not to (just the request)

Because SQS is bound to Lambda (via AWS::Lambda::EventSourceMapping), the execution on the Lambda qualifies as synchronous, not asynchronous

In the synchronous case, the Lambda destination (if configured via AWS::Lambda::EventConfig) is ignored

Although AWS::Lambda::EventSourceMapping supports DestinationConfig, this is not supported when the source is SQS

The only way I can appear to handle an error message in such a case is via the SQS RedrivePolicy field - but this configures a dead letter queue, not a destination (ie no error trace)

Is there any way to capture the error trace in such a situation ?


Solution

  • You can capture lambda errors in your scenario using CloudWatch subscriptions.

    CloudWatch will raise an event to Lambda or Kinesis if it receives a log entry matching a log group (e.g. function name) and text filter.

    You job is to set up the subscription in CloudWatch and log errors in your lambda.