1

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.

11
  • Did you test your lambda function to check if all the steps run smoothly? Commented Oct 20, 2015 at 8:40
  • I have verified same with Get request. I am able to read data from Dynamo using same lambda function. Commented Oct 20, 2015 at 8:42
  • There is a way to test the lambda function itself by pressing 'test' button, it will run the function and give you the log. You can do that and see what console.log gives you Commented Oct 20, 2015 at 8:43
  • I have verified it using test button. here is what I am getting in logs. 2015-10-20T08:27:48.090Z 7130dc0f-7704-11e5-90c5-d181341d7eff [ 'Within upsert meter Info: 1234456' ] END RequestId: 7130dc0f-7704-11e5-90c5-d181341d7eff REPORT RequestId: 7130dc0f-7704-11e5-90c5-d181341d7eff Duration: 652.26 ms Billed Duration: 700 ms Memory Size: 128 MB Max Memory Used: 37 MB Commented Oct 20, 2015 at 8:45
  • Can you check that the docClient is initialized and you can put something into another table, just to check? Commented Oct 20, 2015 at 8:47

1 Answer 1

2

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);
    }
  });
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.