Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I am using nodeJS sdk to put the item to dynamoDB, The item is:

{

   "eventId": date + '-' + eventName + '-' + eventPurpose,

   "eventName": eventName,

   "eventPurpose": eventPurpose,

   "eventDates": eventDates,

   "attendees": attendees

 }

The present code for the putting the item in dynamoDB:

  const params = {

    TableName: "event",

    Item: {

        "eventId": date + '-' + eventName + '-' + eventPurpose,

        "eventName": eventName,

        "eventPurpose": eventPurpose,

        "eventDates": eventDates,

        "attendees": attendees

    },

    ReturnValues: "ALL_OLD"

  };

  dynamo.put(params, (err, data) => {

    console.log("coming here");

    if (err) {

      console.log("error : " + JSON.stringify(err));

    }

    console.log("data" + JSON.stringify(data));

    cb(null, data);

  });

The insertion happens correctly and the return value is an empty object.

I would like to return the inserted item. I found this doc. But this returns only in case of updating the old value. I could not find any other useful info other than this.

Is there any workaround or we simply need to query using get method with the primary key?

closed

1 Answer

0 votes
by (44.4k points)
selected by
 
Best answer

In the callback, pass the params.item:

 dynamo.put(params, (err, data) => {

        if (err) {

          cb(err);

        }

        cb(null, params.Item);

      });

Also in the callback, pass err too.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer

Browse Categories

...