Search code examples
node.jsaws-sdkamazon-sqsaws-sdk-jsaws-sdk-nodejs

Get pending Message count from AWS SQS queue Using nodeJs


I am a new be to AWS. I have a doubt is there any way to get number of messages(total count of messages) pending in AWS-SQS queue using NodeJs. If there is any way to get the count please help friends to solve


Solution

  • Thank you Tuan Anh Tran

    var AWS = require('aws-sdk');
    
    // Set the region 
    AWS.config.update({
     region: 'REGION'
    });
    
    // Create the SQS service object
    var sqs = new AWS.SQS({
      apiVersion: '2012-11-05'
    });
    
    // Set params
    var params = {
     QueueUrl: queueURL,
     AttributeNames : ['ApproximateNumberOfMessages'],
    };
    
    sqs.getQueueAttributes(queParams, function(err, data){
       if (err) {
              console.log("Error", err);
            } else {
              console.log(data);
            }
     });