0

I have set up a lambda function and an SQS service. I want the events from the SQS service to get consumed by the lambda function.

SQS configuration

enter image description here enter image description here

All the other configuration is set to match the default.

Lambda trigger

enter image description here

Lambda configuration

enter image description here

The code used is from the sqs-poller template (and the configuration too)

Code configuration

I'm using the following code to send the event. I run the code with the following command

AWS_SDK_LOAD_CONFIG=true AWS_SHARED_CREDENTIALS_FILE=./credentials node sqs.js

That works fine because I'm seeing the messages in the monitoring panel of the SQS service.

Any idea why events are not being consumed by my lambda function?

Antonio Gamiz Delgado
  • 1,871
  • 1
  • 12
  • 33
  • Did you check if there is actually an item in the queue to recieve? – raupach Jul 20 '21 at 09:32
  • Are you sure that the lambda is not getting triggered? Maybe it does but it doesn't read the event object properly? – Nir Alfasi Jul 20 '21 at 09:34
  • raupach I can see the events being received in the monitoring panel. Nir Alfasi, if that was the case, I would see logs in the Cloud Watch pane from my lambda. – Antonio Gamiz Delgado Jul 20 '21 at 09:40
  • 1
    Can you verify lambda permissions, both execution role and invocations? – Marcin Jul 20 '21 at 10:04
  • I was missing a role, thanks! – Antonio Gamiz Delgado Jul 20 '21 at 10:41
  • I am also having the same kind of issue. Standard queue is configured as trigger for lambda (micronaut), but when message is pushed to the queue that message disappears from the queue, but there is no log in the function (cloud watch log). No idea what is happening. I have assured that queue is being read from that lambda function only. Also this function just works fine when I test it from the lambda console. – Jignesh M. Khatri Aug 30 '22 at 11:35

1 Answers1

3

It would appear that you have two competing concepts in your architecture.

Amazon SQS and AWS Lambda

When an Amazon SQS queue is configured as a trigger to an AWS Lambda function, the AWS service polls the SQS queue looking for messages. When message(s) are found, the Lambda function is invoked, with the messages being passed to the function via the event variable.

The Lambda function can then process those messages, reading the detail of the messages from the event variable.

If the Lambda function completes without error, the AWS service will automatically delete the messages from the SQS queue. If there was an error in the function, the messages will automatically reappear on the SQS queue after the invisibility period has expired.

At no time does the AWS Lambda function actually call the Amazon SQS service to receive or delete messages. Rather, it is given the messages when it is invoked.

SQS Poller

You mention that you are using an sqs-poller class. I'm not sure whether you are referring to Receiving Messages Using the QueuePoller Class in Amazon SQS - AWS SDK for Ruby or @jishimi/sqs-poller - npm.

Nonetheless, polling is a traditional way that worker processes retrieve messages from an SQS queue, and then delete the messages after they are processed. The process is:

  • They ask check whether there are messages available in the SQS queue
  • If so, they invoke a worker
  • When the worker is finished, they delete the message

You should notice that these are the same steps that the AWS Lambda service does when SQS is configured as a trigger for an AWS Lambda function. Therefore, using a polling architecture is incompatible with using SQS as a trigger for an AWS Lambda function.

You should pick one or the other, not both.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470