Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

trying to trigger my lambda function from sqs and it is triggering lambda but no message in queue

I am trying to trigger my lambda function from SQS delay queue and it is triggering lambda but no message in queue. Even when I check on aws console there is a message delay and when that delay time is over. It trigger my lambda function but when my lambda try to get the list of messages it shows empty list. The other thing is when I remove the lambda trigger after that whenever I send a message to queue it shows message available after the delay time. So it's working as expected without adding a trigger to lambda but when I add trigger my lambda is not receiving any message to process.

I have tried various things but nothing worked out. my Default Visibility Timeout: 30seconds and Receive Message Wait Time: 0 seconds and Delivery Delay: 10 seconds.

Using below code to fetch the messages from sqs and it always return empty list :

final ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(SQS_URL);
        final List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages();

I am new to aws and don't know what to do, due to this issue stuck in a deadlock. Please help.

like image 849
Sneha Avatar asked Jan 26 '26 03:01

Sneha


1 Answers

If you have configured the Amazon SQS queue to trigger an AWS Lambda function, then the function should not call ReceiveMessage().

Instead, the message is automatically taken from the SQS queue and is passed to the Lambda function via the event parameter.

For sample code, see: Sample Amazon SQS Function Code - AWS Lambda

The Lambda function should loop through the messages passed to the function. When the function ends, the messages will automatically be deleted.

like image 92
John Rotenstein Avatar answered Jan 27 '26 22:01

John Rotenstein