Reputation: 139
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?
Upvotes: 0
Views: 9522
Reputation: 78573
If I understand your question, you need to:
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.
Upvotes: 2