Back

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

I'm using AWS Lambda and try to write something to AWS DynamoDB. I use the following code:

var tableName = "locations";

var item = {

    deviceId: {

        S: event.deviceId

    },

    timestamps: {

        S: event.timestamp 

    }

}

var params = {

    TableName: tableName,

    Item: item

};

 

dynamo.putItem(params, function(err, data) {

    if (err) {

        context.fail(new Error('Error ' + err));

    } else {

        context.success(null);

    }

});

And I get the following error:

returns Error ValidationException: One or more parameter values were invalid: Type mismatch for key deviceId expected: S actual: M

1 Answer

0 votes
by (44.4k points)

AWS SDK for Node.js has changed. So, if you are using:

var doc = require('dynamodb-doc');

var dynamo = new doc.DynamoDB(); 

It has to be like this:

var tableName = "locations";

var item = {

    deviceId: event.deviceId,

    timestamp: event.timestamp,

    latitude: Number(event.latitude),

    longitude: Number(event.longitude)

}

var params = {

    TableName: tableName,

    Item: item

};

Related questions

Want to get 50% Hike on your Salary?

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

0 votes
1 answer

Browse Categories

...