node.js - Creating an AWS SQS queue -
i trying create sqs queue on aws ec2 instance using node.js. same instance, can access s3 , list buckets, etc. using node.js. instance has iam role granting full access s3 , sqs.
executing below code fails , cannot figure out why. more interesting pc code works.
var aws = require('aws-sdk'); aws.config.update({region:'eu-central-1'}); //console.log("awsv "+aws.version); --> 2.3.5 var sqs = new aws.sqs(); var params = { queuename: "myqueue1" }; sqs.createqueue(params, function(err, data) { if (err) console.log(err, err.stack); // error occurred else { if(data) console.log(data); // successful response else console.log("other unknown error"); } });
error message:
/home/ubuntu/aws-nodejs-sample/node_modules/aws-sdk/lib/http/node.js:121 callback(); ^ typeerror: undefined not function @ writable.writer._write (/home/ubuntu/aws-nodejs-sample/node_modules/aws-sdk/lib/http/node.js:121:7) @ writable.write (_stream_writable.js:176:8) @ write (_stream_readable.js:481:24) @ array.foreach (native) @ flow (_stream_readable.js:493:19) @ _stream_readable.js:458:7 @ process._tickcallback (node.js:427:13) @ process._makecallback (node.js:345:15)
it turns out, quick test script calling cli functions works:
var aws = require('aws-sdk'); aws.config.region = 'eu-central-1'; var qurl="https://sqs.eu-central-1.amazonaws.com/......./awsquerytest"; var queue = new aws.sqs({params: {queueurl: qurl}}); // using url queue var receipthandle; var fs = require('fs'); var child = require('child_process').exec('aws sqs receive-message --queue-url https://sqs.eu-central-1.amazonaws.com/....../awsquerytest'); child.stdout.on('data', function(data) { var x= data.tostring(); console.log(data.tostring()); fs.writefile("/home/ubuntu/aws-nodejs-sample/output",x,function(err){ if(err){ return console.log(err); } console.log("oldu"); }); }); child.stderr.on("data", function (data) { console.log(data.tostring()); });
how can explained?
looks it's differing version of node have installed on ubuntu server vs. local machine.
what node --version
running locally vs. on server?
Comments
Post a Comment