5
votes

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.

2
Have you tried simply throwing an exception from inside the Lambda function? That should be considered a failure, the same as the other failures you mentioned.Michael - sqlbot
My handler class implements aws RequestHandler interface, which declares a method handleRequest() without any exception in the declaration. So in my overidden method, i have to use try catch block. Code. I can not simply throw exception.Vinod Singh

2 Answers

6
votes

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.

1
votes

In the DLQ setting of a Lambda you specify a SNS topic or a SQS Queue. In your setup you have configured the DLQ to be a SQS queue. This is a regular SQS Queue. Using the SQS Java SDK you can post a message to that SQS Queue.

here are few references: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-send-message.html

To get the Queue URL you can use these: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_GetQueueUrl.html

Or through Java: https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/sqs/AmazonSQSClient.html#getQueueUrl-java.lang.String-