2
votes

I try to pull messages from a SQS queue(not FIFO) but it doesn't work. I have a lambda writing a value in a DynamoDB, triggering another Lambda creating a SQS message. Then I created a Lambda function with rights ReceiveMessage, GetQueueAttributes and DeleteMessage and added a "Trigger for Lambda Functions" in SQS giving permissions to my new lambda function. Whenever an entry is added to the database my last lambda function is triggered so the trigger seems to work. When I try to get the entries using sqs.receivemessage(...) it waits until the WaitTimeSeconds period is passed and I receive an answer like this:

{
"ResponseMetadata": {
    "RequestId": "b1e34ce3-9003-5c00-a3d8-1ab75ba132b8"
    }
}

unfortunately no Message object is added. I also tried wrapping this call in a loop to try it several times in a row as suggested on other pages but unfortunately he just runs until the timeout is reached and I don't get the message. When the lambda is running I can see the message in the "Messages in the flight" list.

I tried modifying the timeouts, the way I call the function and googled a lot, but unfortunately I still receive no messages.

Any ideas?

Here is my code:

'use strict';
var AWS = require("aws-sdk");
AWS.config.update({region: 'eu-central-1'});
var sqs = new AWS.SQS({apiVersion: '2012-11-05'});
exports.handler =(event, context, callback) => {
var params = {
  QueueUrl: 'https://sqs.eu-central-1.amazonaws.com/476423085846/email', 
  AttributeNames: ['All'],
  MaxNumberOfMessages: 5,
  MessageAttributeNames: [
    'email',
    'hash'
  ],
  WaitTimeSeconds: 10
};
sqs.receiveMessage(params, function(err, data) {
  if (err)
  {
      console.log(err, err.stack); // an error occurred
  }
  else
  {
      console.info('DATA\n'+JSON.stringify(data));
  }
}
}

My SQS settings:

Default Visibility Timeout: 5min, Message Retention Period: 4 days, Maximum Message Size: 256kb(my messages should be way smaller), Delivery Delay: 0sec, Receive Message Wait Time: 10sec

Thanks in advance :)

Regards Christian

1

1 Answers

1
votes

With AWS Lambda SQS integration, AWS handles polling the SQS queue for you. The SQS message(s) will be in the event object that is passed to the Lambda function invocation. You should not be calling receiveMessage directly in that scenario.