2017-05-25 73 views
0

我的問題如下:Node.js的錯誤

ABC拉姆達觸發另一個lambda(命名爲:khjj) 一切都正常,我唯一的事情是,在CloudWatch的日誌,甚至在局部如果我運行abc lambda函數來觸發khjj lambda,那麼我的請求之後會出現套接字掛起錯誤。

我的ABC拉姆達讀取來自一個發電機分貝表和逐行一個數據觸發khjj功能,在ABC拉姆達的代碼是:

var sendData = module.exports = { 
    data : function(){ 
    return new Promise(function (resolve, reject) { 
    arrayData = [] 

    // here table.get is a function in the same file for getting the 
    // data from the dynamo db table 
    table.get("Table1").then(function(response){ 
    _.forEach(response, function(data){ 
     var obj = {}; 
     obj.value1 = data.value1; 
     obj.value2 = data.value2; 
     obj.value3 = data.value3; 
     obj.value4 = data.value4; 
     obj.value5 = data.value5; 
     obj.value6 = data.value6; 
     obj.value7 = data.value7; 
     arrayData.push(obj) 
    }) 
    Promise.all(arrayData).then(function(objs){ 
     async.each(objs, function(data, callback){ 
     request({ 
      headers: {'Content-Type':'application/json'}, 
      url : // here I used lambda khjj url here, 
      method: 'POST', 
      body: company, 
      json: true 
     }, function (err, res, body) { 
      if(!_.isNil(err)){ 
      console.log(err); 
      console.log('error in triggering') 
      } else { 
      // tried this callback as well to stop that error of socket hangup 
      callback(null, 'success') 
      } 
      }) 
     }, function(err){ 
      console.log() 
     }) 
     }, function(err){ 
     console.log(err) 
     }) 
    }, function(err){ 
     console.log('error in getting data from table :', err) 

    }) 
    resolve(true); 
}) 
} 

現在上述lambda函數觸發「khjj」拉姆達所以我在「khjj」拉姆達函數中使用,因此在這裏獲得請求的代碼awsServerlessExpress功能:

app.post('/called/by/abc/lambda', function(req, 
    resp){ 
     check.message(request).then(function(response){ 
     resp.write('success') 
     resp.end(); 
     }, function(err){ 
     console.log(err) 
     resp.end(); 
    }) 
    }) 

插座錯誤是在上面的拉姆達即khjj到來,找遍了網甚至計算器和aws論壇,但沒有得到Ÿ解決方案

即使考慮過這個網站:https://gregjs.com/javascript/2015/how-to-scrape-the-web-gently-with-node-js/

請任何幫助就可以了。謝謝。

CloudWatch的錯誤:

2017-05-25T13:30:15.043Z 009c3110-414e-11e7-99b5-b3bd2686fba3  
    { Error: socket hang up 
    at createHangUpError (_http_client.js:253:15) 
    at Socket.socketOnEnd (_http_client.js:345:23) 
    at emitNone (events.js:91:20) 
    at Socket.emit (events.js:185:7) 
    at endReadableNT (_stream_readable.js:974:12) 
    at _combinedTickCallback (internal/process/next_tick.js:80:11) 
    at process._tickDomainCallback 
    (internal/process/next_tick.js:128:9) code: 'ECONNRESET' } 
+0

您能否將堆棧跟蹤記錄到cloudwatch並在此處提供? –

+0

是的,我更新了日誌錯誤。 – learner

回答

0

我解決我的問題上面,錯誤是未來不僅是因爲在某處,我不處理的承諾的代碼拒絕正常。