我正在使用aws-sdk for javascript。下面aws-sdk崩潰nodejs程序
該代碼在一個獨立的程序
//program.js
const AWS = require('aws-sdk');
const firehose = new AWS.Firehose({
accessKeyId: "XXX",
secretAccessKey: "YY"
});
const params = {
DeliveryStreamName: 'demo1',
Record: {
Data: new Buffer("Hello World")
}
};
firehose.putRecord(params, function (err, data){
if (err) {
console.log(err);
return;
}
console.log(data); // successful response
});
再次使用時正常工作,上面的代碼正常工作作爲一個獨立的文件。數據被推入流水,然後進一步下移至Redshift。 所以如果我執行
node program.js
我能看到我的紅移數據。好極了!!
=============================
但是,我真正想實現的是將數據推到當我的快速應用程序中某條路線受到撞擊時流水。所以,我採取完全相同的代碼如上,貼在我的路線
// router.js
const AWS = require('aws-sdk');
const firehose = new AWS.Firehose({
accessKeyId: "XXX",
secretAccessKey: "YY"
});
router
.get('/v1/locations/:id?', (req, res) => {
const params = {
DeliveryStreamName: 'demo1',
Record: {
Data: new Buffer("Hello World")
}
};
firehose.putRecord(params, function (err, data){
if (err) {
console.log(err);
return;
}
console.log(data);
});
// do the work that needs to be done for this route and send a response
res.send("some data");
});
執行firehose.putRecord的那一刻..它崩潰我的程序,出現以下錯誤:
```
TypeError: doneCallback.cal is not a function
at Request.callListeners (/api-project/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
at callNextListener (/api-project/node_modules/aws-sdk/lib/sequential_executor.js:95:12)
at /api-project/node_modules/aws-sdk/lib/event_listeners.js:74:9
at finish (/api-project/node_modules/aws-sdk/lib/config.js:315:7)
at /api-project/node_modules/aws-sdk/lib/config.js:333:9
at Credentials.get (/api-project/node_modules/aws-sdk/lib/credentials.js:126:7)
at getAsyncCredentials (/api-project/node_modules/aws-sdk/lib/config.js:327:24)
at Config.getCredentials (/api-project/node_modules/aws-sdk/lib/config.js:347:9)
at Request.VALIDATE_CREDENTIALS (/api-project/node_modules/aws-sdk/lib/event_listeners.js:69:26)
at Request.callListeners (/api-project/node_modules/aws-sdk/lib/sequential_executor.js:101:18)
我不明白爲什麼這段代碼崩潰了我的快車程序。這是aws-sdk庫中的bug還是我做錯了什麼?
終於明白了這個問題。 aws-sdk沒有正確安裝(我不知道這是怎麼發生的)。在第115行的文件sequential_executor.js中有一個語句** doneCallback.call ** ...但是在我的文件中,該語句只是** doneCallback.cal ** .. –