Reputation: 959
I am new to AWS and Lambda. I created a test aws account and in DynamoDB created a table called guestbook with fields data and message. I tried the below code to insert record into table using lambda function.
and when I try to test this function, its giving this error
{ "errorMessage": "Syntax error in module 'lambda_function'" }
Can someone help me understand what is going wrong here.
FYI, I copied the code from example on Youtube .
Here is the code.
console.log('Starting Function');
const AWS = require ('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient({ region: 'us-west-1' });
exports.handle = function (e, ctx, callback) {
var params = {
item: {
date: Date.now(),
message: "this is test"
},
TableName: 'guestbook'
};
docClient.put(params, function (err, data) {
if (err) {
callback(err, null);
} else {
callback(null, data);
}
});
}
Upvotes: 0
Views: 854
Reputation: 1058
The params was incorrect. The api's guide is here. The correct params should be like this.
console.log('Starting Function');
const AWS = require ('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient({region: 'us-west-1'});
exports.handle = function (e,ctx, callback){
var params = {
TableName: 'guestbook'
Item: {
date: Date.now(),
message: "this is test"
}
}
docClient.put(params, function(err, data) {
if (err) {
callback(err, null);
} else {
callback(null,data);
}
});
Upvotes: 2