1

I am not able to figure out how to use the data retrieved from dynamodb.getItem. I would like to return the result of getItem to the user.

Foe example, the code

dynamodb.getItem(params, function(err, data) {
      if (err) console.log(err); // an error occurred
      else  console.log(data);
}

will log the data to console. How can I return the data to the called function?

Thank you for the help.

VinayBS
  • 389
  • 5
  • 19

1 Answers1

0

There is no straight forward way that you can return the data form getItem ( aws dynamoDB), You have to supply a callback function to getItem or you have to use Request.send(callback) with callback.It is same like any asynchronous call and you cannot return the response from an asynchronous call.

For detail about how to return the response from an asynchronous call please visit the link I provided in the comment, above under the question.

Here is example code you can user.

var callback: function(err,data){
     /// use data.
};

dynamodb.getItem(params,callback); 
Ihtsham Minhas
  • 1,415
  • 1
  • 19
  • 31
  • 3
    Please update your answer to include context around your solution – Malkus Sep 23 '15 at 15:21
  • 1
    Please consider editing your post to add more explanation about what your code does and why it will solve the problem. An answer that mostly just contains code (even if it's working) usually wont help the OP to understand their problem. – SuperBiasedMan Sep 23 '15 at 16:52