Chetan Shirke
Chetan Shirke

Reputation: 904

AWS DynamoDB node.js put request doesn't put data into Dynamo table

I am using following code to ingest data to DynamoDB.

Code to read from Kinesis

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);
      }
   });
}

I am not able to see error handler sysouts in cloudwatch logs as well as I am not able to see data in DynamoDB.

Below are sample logs from cloudwatch

"Within upsert Info: 1234456"

I am not able to see any error logs related to PutItem function in cloudwatch lambda function logs.

Please suggest what I am doing wrong here.

Upvotes: 1

Views: 1666

Answers (1)

Chetan Shirke
Chetan Shirke

Reputation: 904

I found solution for this problem on below link.

Querying DynamoDB with Lambda does nothing

This was because of context.succeed call used in lambda handler as well.

    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);
    }
  });
};

Upvotes: 2

Related Questions