1

I'm using dynamo-db scan to get this a database table in JSON format, but it seems to not be working

var doc = require('dynamodb-doc');
var dynamo = new doc.DynamoDB();

exports.handler = function(event, context) {

dynamo.scan({ 'TableName' : 'DATABASE_NAME' }, function(err, data) {
    console.log('this doesnt print');
    if (err) console.log(err, err.stack)
    else console.log(data);
});
context.succeed('ding');

I don't believe it is entering the callback function at all, since 'this doesnt print' doesn't print. Any ideas? Thanks :)

2
  • Can you show how do you run this? Commented Feb 2, 2016 at 18:48
  • is your exports.handler function even called? Commented Feb 2, 2016 at 18:48

1 Answer 1

1

You are calling context.succeed() before the DynamoDB call finishes. You need to look into how asynchronous calls work in NodeJS. Try something like this:

var doc = require('dynamodb-doc');
var dynamo = new doc.DynamoDB();

exports.handler = function(event, context) {

dynamo.scan({ 'TableName' : 'DATABASE_NAME' }, function(err, data) {
    console.log('this doesnt print');
    if (err) {
      console.log(err, err.stack)
      context.fail(err);
    }
    else {
      console.log(data);
      context.succeed('ding');
    }
});
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.