11

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 1

34

This happened because the aws sdk for Nodejs had changed!

If you are using:

var doc = require('dynamodb-doc');
var dynamo = new doc.DynamoDB();

Then the parameters to the putItem call (and most other calls) have changed and instead needs to be:

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
};

Read all about the new sdk here: https://github.com/awslabs/dynamodb-document-js-sdk

Sign up to request clarification or add additional context in comments.

3 Comments

The AWS-SDK now actually supports a DocumentClient! Check it out here docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/…
This fixed it. Thank you! AWS needs to update their documentation.
AWS boilerplate still has this issue as of 2018 :(

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.