DEV Community

Discussion on: Error handling in AWS Lambda triggered by SQS events

Collapse
 
chitranjali_e profile image
anjali

Hey, Thanks much for this article, really helpful, But when you used RedrivePolicy method, Don't you need to attach your source queue to the lambda through serverless.yml? or Are you doing it manually?, like giving the "Dead-letter queue service" Field in Lambda. (This comes in asyncronous invocation tab in lambda whene using consol), If this isn't given, how your lambda will send the failures to source queue's?

Collapse
 
piczmar_0 profile image
Marcin Piczkowski • Edited

Hi, My source queue (MyQueue) is attached to lambda in serverless.yaml via events.sqs section. What I do later is defining a new queue (ReceiverDeadLetterQueue) as a dlq for the source queue, instead defining dlq for lambda. In AWS you can define fallback behavior (dlq) either on Lambda or on SQS. I took the second approach, because for the first approach I would need to have SNS topic and then subscribe queue to it, which I think would be too much. So using dlq on SQS (source queue) was simpler, even if I had to write some cloudformation piece of code in resources section of my serverless.yaml. So now Lambda knows nothing about dlq. This is SQS MyQueue which knows that if the same message returns (which happens when Lambda fails) it should pass it to dlq. Hope you got the idea :)