Search code examples
amazon-web-servicesamazon-s3aws-lambdadead-letter

Is there any way to explicitly send event message to dead letter queue from inside AWS lambda function on certain condition?


I'm trying to send s3event message to rabbitmq by invoking AWS lambda function. I have configured SQS as my dead letter queue(DLQ). I know the message is sent to DLQ when there failure in invocation of lambda or situations like timeouts or resource constraints. My question is ,I want to send event message to DLQ from inside lambda function on certain condition like if rabbitmq is down or some other condition of my interest. Is there any possiblity for the same? Should I throw exception or there is some other better approach to send event message to DLQ.

I'm using java for development and connecting to rabbitmq from my lambda function.


Solution

  • The DLQ is simply an SQS Queue, so you could send a message to it like you would any other queue. You would want it to be formatted the same way that Lambda natively puts message in the DLQ so that whatever processing you have on the DLQ can perform the same way for all messages. You would want to ensure that you treat the lambda as successfully executed in this instance though so that the normal DLQ process doesn't pick up the same message twice.