7

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.

Vinod Singh
  • 145
  • 1
  • 3
  • 8
  • 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 Mar 21 '18 at 22:35
  • 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 Mar 22 '18 at 05:21
  • I'm obviously late to the game here, but for the sake of others. In Java you can throw "unchecked" exception types from any method regardless of if they've been specified in the method definition (it's considered best practice NOT to specify them in the method definition as that forces the implementor to handle them, which may not be practical). Most commonly, this means that derivatives of RuntimeException can be thrown. https://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html – Avery Michelle Dawn Apr 13 '22 at 19:41

2 Answers2

10

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.

Jarred Olson
  • 3,075
  • 1
  • 19
  • 34
1

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-

Yogesh_D
  • 17,656
  • 10
  • 41
  • 55