Ted Barnett
Ted Barnett

Reputation: 21

dynamodDB putItem: "UnexpectedParameter: Unexpected key 'L' found in params.Item"

I am attempting to "putItem" a new record into a dynamoDB database but failing on attempts to include an Array in the data. My params.Item looks like the following:

msg.params.Item = {
    fileName: {S: "filename"}, // database is keyed on filename
    userEmail: {S: "emailaddress"},
    transcription: {S: "text here"},
    features: {L: [ { "relevance": {S: "0.900906"}, "text": {S: "keyword"}} ]}
};

I repeatedly get the error "UnexpectedParameter: Unexpected key 'L' found in params.Item['features']". I assume I have somehow formatted the "features" array incorrectly, but I can't figure out where my error is. I have tried many different incantations of the array. Any help appreciated as there are shockingly few online examples of working dynamoDB putItem javascript using arrays.

FYI: I am using node.js inside of Node-RED, which may explain the odd code, but I had this working just fine with a Cloudant database before. Only dynamoDB is choking on this array.

Upvotes: 2

Views: 14994

Answers (3)

Paul Razvan Berg
Paul Razvan Berg

Reputation: 21390

You may want to check your apiVersion. I ran into this issue because I wasn't using the latest one, which is 2012-08-10, not 2011-12-05.

Upvotes: 0

rob
rob

Reputation: 156

You're missing M for map:

features: {L: [ { "relevance": {S: "0.900906"}, "text": {S: "keyword"}} ]}

should be

features: {L: [ {M: {"relevance": {S: "0.900906"}, "text": {S: "keyword"}}} ]}

Upvotes: 5

notionquest
notionquest

Reputation: 39186

The below code should create the item successfully. The DynamoDB data type need not be mentioned separately as long as it follows the below mapping.

JavaScript Type --> DynamoDB Type

Array --> L

Object --> Map

JavaScript data type to DynamoDB data type mapping

var docClient = new AWS.DynamoDB.DocumentClient();    
var table = "files";    
var params = {
    TableName:table,
    Item:{
        "fileName" : "file1",
        "userEmail" : "[email protected]",
        "transcription" : "transcription text",
        "features" : [{ "relevance":  "0.900906", "text":  "keyword"}]

    }    
};

console.log("Adding a new item...");
docClient.put(params, function(err, data) {
    if (err) {
        console.error("Unable to add item. Error JSON:", JSON.stringify(err, null, 2));
    } else {
        console.log("Added item:", JSON.stringify(data, null, 2));
    }
});

Upvotes: 2

Related Questions