0

I have a DynamoDB table called Wishlist, and an existing DynamoDB Item which I'm calling "monitor".

I am trying to write a Lambda function that updates the "monitor" item as follows:

  • takes the user's login ID, appends @gmail.com to it, and writes it to a new email attribute

  • writes a timestamp to the item

Here is my code:

console.log('Loading function');
var doc = require('dynamodb-doc');
var db = new doc.DynamoDB();

exports.handler = function(event, context) 
{
     var username  = event.username;
     var email = event.username+"@gmail.com";
     console.log(username + "," + email);

     var tableName = "WishList";
     var item = {
           "username":username,
           "email":  email,     
     };

     var params = {
         TableName:tableName, 
         Item: item
     };

     console.log(params);
     db.putItem(params, function(err,data){
         if (err) console.log(err);
         else console.log(data);
     });
};

How do I read the existing "monitor" item so that I can update it with putItem?

2
  • What is the primary key of the table? Commented Nov 13, 2017 at 23:45
  • Primary partition key - Device (String) @MarkB Commented Nov 14, 2017 at 0:04

1 Answer 1

2

If I understand your question, you need to:

  • get the existing item by its key using getItem
  • modify the returned item
  • put the modified item using putItem

Alternatively, you can simply use updateItem which will edit an existing item's attributes, or add a new item to the table if it does not already exist.

You can see sample code here.

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.