I’m playing around with SQS and Lambdas and have a minimal case with a queue and a Lambda triggered by a queue event. The strange thing is that if I add a message to the queue from the console, I can see from the CloudWatch logs that the Node.JS lambda is triggered but all my lambda currently does is console.log of the event. I was under the impression that once visibility timeout (15s) was reached, it would fire again but that is not the case.
And it hasn’t been returned to the queue either. I was under the impression that messages weren’t supposed to disappear from a queue unless explicitly deleted(?)
Thankful for pointers,
Nik
2
Answers
You are correct that messages should not disappear from the queue unless explicitly deleted. I can think of two reasons for the behavior you’ve described:
maxReceiveCount
set to 1;MessageRetentionPeriod
.When an Amazon SQS queue has been configured as a trigger for an AWS Lambda function, the Lambda service automatically retrieves the message(s) from the queue and passes it to the Lambda function via the
event
parameter. (Note: It might contain multiple messages.) The messages are made temporarily invisible.When the Lambda function exits without generating an error, the SQS message is automatically deleted from the queue. This is why your message disappeared.
If, instead, your had code running somewhere that polled the queue and called
ReceiveMessage()
, then it would behave as you describe — the message would become invisible and, if the message was not deleted within a certain time (or a heartbeat generated), the message would become visible again.Bottom line: When triggering a Lambda function from an SQS queue, the Lambda services does all the interaction with the queue for you. Your Lambda function doesn’t need any SQS-related code.