0 votes
1 view
in AWS by (19.2k 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.6k 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

};

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...