Monday, February 25, 2019

Nodejs Queue with AWS SQS

Step 1: Install docker


This digital ocean article describes properly how to install docker on ubuntu
install docker article



Step 2: Install AWS SQS queue service docker image in local 

You can manage Nodejs queues using AWS SQS in your local machine. 

https://github.com/vsouza/docker-SQS-local

docker pull vsouza/sqs-local;
docker run -d -p 9324:9324 vsouza/sqs-local;


Now this sqs queue run locally using 9324 port.
SQS_HOST=http://localhost:9324
Step 3: Install AWS SDK for Nodejs

https://www.npmjs.com/package/aws-sdk


Step 4: Configure to use SQS in local

let SQS_HOST="http://localhost:9324";

const sqsConfig = {
    endpoint: new AWS.Endpoint('https://sqs.us-west-2.
    amazo.com/22222/queue.sqs'),
    accessKeyId: 'dadada',
    secretAccessKey: 'aadwfe',
    region: 'us-west-2'};

if (SQS_HOST) {
    sqsConfig.endpoint = new AWS.Endpoint(SQS_HOST);
}
const sqs = new AWS.SQS(sqsConfig);


var params = {
    QueueName: 'test', /* required */    // Attributes: {    //     '<QueueAttributeName>': 'STRING_VALUE',    //     /* '<QueueAttributeName>': ... */    // }};

sqs.createQueue(params, function(err, mysql_test) {
    if (err){
        console.log(err, err.stack); // an error occurred    }
    else {

        console.log('Success');
    }
});

You can find SQS queue (aws-sdk node package) documentation below.
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SQS.html#createQueue-property 

Share/Bookmark

0 comments:

Post a Comment