Search code examples
node.jsamazon-web-servicesamazon-sqsaws-sdk-nodejs

How to read messages from aws sqs fifo queue?


I am trying to read from an SQS Fifo Queue, using javascript SDK,
I'm using the receiveMessage method of AWS SQS SDK to do do,
But I'm getting an error while doing so.

Following is the code snippet I'm running -

let AWS = require('aws-sdk');
let util = require('util');
AWS.config.update({region: 'us-east-1'});

let test = async() => {
    let sqs = new AWS.SQS();

    let params = {
        QueueUrl: 'sqs.us-east-1.amazonaws.com/awsAccountId/sqsQueueName.fifo'
    };

    let sqsReceiveMessage = util.promisify(sqs.receiveMessage).bind(sqs);
    let messages = await sqsReceiveMessage(params);
    console.log(messages);
};
test();

I am getting the following error -

(node:13221) UnhandledPromiseRejectionWarning: InvalidAddress: The address sqs.us-east-1.amazonaws.com/awsAccountId/sqsQueueName.fifo is not valid for this endpoint.

Following is the SQS queue URL, I'm trying to read - enter image description here

I'm using the following as a reference -
1. https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SQS.html#receiveMessage-property
2. https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SQS.html#receiveMessage-property
3. https://www.reddit.com/r/aws/comments/5mclde/sqs_cli_aws_sqs_getqueueurl_returns_different_url/
4. https://www.bogotobogo.com/DevOps/AWS/aws-Amazon-SQS-Simple-Queue-Service-with-NodeJS-AWS-SDK.php


Solution

  • Have you tried using http:// in front of the queue name? I don't use node.js, but in c# I give it the whole url, including the http://