4
我想從使用node.js的EC2實例在AWS上創建一個SQS隊列。 從同一個實例中,我可以使用node.js訪問S3並列出存儲桶等。該實例具有IAM角色,授予對S3和SQS的完全訪問權限。創建一個AWS SQS隊列
執行下面的代碼,但失敗,我不明白爲什麼。更有趣的是,從我的電腦中,代碼實際上起作用。
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); // an error occurred
else {
if(data)
console.log(data); // successful response
else
console.log("Other unknown error");
}
});
錯誤消息:
/home/ubuntu/aws-nodejs-sample/node_modules/aws-sdk/lib/http/node.js:121
callback();
^
TypeError: undefined is not a function
at Writable.writer._write (/home/ubuntu/aws-nodejs-sample/node_modules/aws-sdk/lib/http/node.js:121:7)
at Writable.write (_stream_writable.js:176:8)
at write (_stream_readable.js:481:24)
at Array.forEach (native)
at flow (_stream_readable.js:493:19)
at _stream_readable.js:458:7
at process._tickCallback (node.js:427:13)
at process._makeCallback (node.js:345:15)
事實證明,一個快速測試用腳本調用CLI函數的實際工作:
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 to 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());
});
這又如何解釋呢?
您是否試過指定api版本?像'new AWS.SQS({apiVersion:'2012-11-05'});' – John
不,但只有最新版本安裝在實例(2.3.5)上。儘管如此,我確實嘗試使用1.0.0,但無濟於事。 – jallmer
嘗試{apiVersion:'2012-11-05'}但再次沒有運氣。 – jallmer