2015-10-20 58 views
1

我正在使用以下代碼將數據提取到DynamoDB。AWS DynamoDB node.js放入請求不會將數據放入Dynamo表

代碼從室壁運動

var AWS = require("aws-sdk"), 
DOC = require("dynamodb-doc"); 
docClient = new DOC.DynamoDB(); 

function upsert(result) { 
    var info = new Info(result); 
    console.log('Within upsert :', info.AcctNo); 
    docClient.putItem({ 
     TableName: "test_lamda_dynamo_table", 
     Item: info 
    }, function(err, data) { 
     if (err) { 
     console.error('error', err); 
     context.done('error', err); 
     } else { 
     console.log('success', data); 
     context.done('success', event.Records); 
     } 
    }); 
} 

閱讀我不能看到CloudWatch的日誌錯誤處理程序sysouts以及我不能看到DynamoDB的數據。

下面是CloudWatch的

"Within upsert Info: 1234456" 

抽樣日誌我不能看到CloudWatch的lambda函數日誌相關PutItem函數的任何錯誤日誌。

請在這裏建議我做錯了什麼。

+0

你測試了你的lambda函數來檢查所有步驟是否順利運行? –

+0

我已通過Get請求驗證。我能夠使用相同的lambda函數從Dynamo讀取數據。 –

+0

有一種方法可以通過按'test'按鈕來測試lambda函數本身,它會運行該函數並給出日誌。你可以做到這一點,看看'console.log'給你 –

回答

2

我在下面的鏈接中找到了這個問題的解決方案。

Querying DynamoDB with Lambda does nothing

這是因爲在lambda處理程序使用,也context.succeed通話。

exports.handler = function(event, context) { 

    event.Records.forEach(function(record) { 
    try { 
     var payload = new Buffer(record.kinesis.data, 'base64').toString('ascii'); 

     console.log('Decoded payload:', payload); 

     upsert(payload, context); 

     // bug 
     context.succeed("Success") 

    } catch (e) { 
     // log error and continue 
     console.error('Error occured while inserting messages to Dynamo' + e); 
    } 
    }); 
};