2
votes

I have lambda function which read sqs messages and process it. I have implement a trigger(lambda trigger) for the integration .

Each time when I push a message to the queue Lambda is getting invoked and from the logs I understood that all the messages are in in-flight status .

 String queueUrl = sqs.getQueueUrl("test_queue").getQueueUrl();
       final ReceiveMessageRequest receiveMessageRequest = new 
  ReceiveMessageRequest(queueUrl);
        int count = getMessagesCount(sqs);

        while(messagesCount > 0) {
            List<Message> messages = 

sqs.receiveMessage(receiveMessageRequest).getMessages();

 logger.info("No.of messages in queue :{} ", count);

See the logs enter image description here

Lambda time out and sqs visibility timeout are 20 minutes. SQS configuration is given below

enter image description here

1

1 Answers

2
votes

When you use SQS integration with Lambda, AWS handles polling the queue for messages and sending them to the Lambda function. The message is in-flight because AWS has already retrieved the message for you. You shouldn't be calling sqs.receiveMessage. You shouldn't even need to use the SQS API at all. The message is in the event object passed to your Lambda function when it is invoked. All you need to do is process the message.