3

I have a simple table in DynamoDb local and try to put an item like this:

var options = {name : "test",
            creator : "Testcreator", description : "test",
            moderators : ["Testmoderator"]};

var obj = {
  name: {"S": options.name},
  restricted: {"BOOL": options.restricted || false},
  creator: {"S": options.creator},
  description: {"S": options.description || ""},
  moderators: {"SS" : options.moderators || []}
};
var params = {
  "TableName": "MY_TABLE",
  "Item": obj,
  Expected: {
    name: {Exists: false}
  }
};
dynamodb.putItem(params, function (err, data) {
    ppJson(err);
});

According to the documentation, boolean values are allowed, put I am getting the following error when I try this code in the DynamoDB Local shell:

"code":"UnexpectedParameter",
"message":"Unexpected key 'BOOL' found in params.Item['restricted']"
...

Is there an error in my code or is this a problem with the javascript API?

AlexanderF
  • 254
  • 3
  • 11
  • 1
    Make sure `options.restricted` is a valid `BOOL` value. Hard code `true` to see if it works. Which of the attributes make your primary key? Also, empty strings ("") are not valid values for attributes of type string. If you don't have an actual string to assign just omit the attribute altogether. – b-s-d Apr 07 '15 at 03:32
  • 1
    I also suggest you using the DynamoDB Document API to assist with the marshaling process: https://github.com/awslabs/dynamodb-document-js-sdk – b-s-d Apr 07 '15 at 03:43
  • Hi, thank you for your suggestions. The Document API looks really helpful. Unfortunately hardcoding true as the value for the field restricted did not work. – AlexanderF Apr 07 '15 at 06:28
  • What is the primary key of your table? – b-s-d Apr 07 '15 at 10:59
  • Ah, sorry, forgot to answer that question. It is the field "name". – AlexanderF Apr 07 '15 at 12:22
  • Would also be helpful to say what version of DynamoDB Local you are using. – mkobit Apr 08 '15 at 21:01
  • Ah yes, I am using dynamodb local 2015-01-27. – AlexanderF Apr 09 '15 at 21:59

1 Answers1

2

I enabled the DynamoDB Local logging to see the internal error being generated by the engine, and here is what I got after trying to put an item like yours:

[LocalDynamoDBServerHandler] - body:
{"TableName":"MY_TABLE","Item":{"name":{"S":"test"},"restricted":{"BOOL":true},"
creator":{"S":"Testcreator"}}}
_LOG_2015-04-07 08:25:26,549 ERROR [com.amazonaws.services.dynamodbv2.local.serv
er.LocalDynamoDBServerHandler] - Unknown error
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized f
ield "BOOL" (class com.amazonaws.services.dynamodbv2.model.AttributeValue), not
marked as ignorable (6 known properties: , "SS", "BS", "B", "S", "NS", "N"])
 at [Source: [B@806204; line: 1, column: 78] (through reference chain: com.amazo
naws.services.dynamodbv2.model.PutItemRequest["Item"]->com.amazonaws.services.dy
namodbv2.model.AttributeValue["BOOL"])

According to the logs, it looks like the only supported types by DynamoDB Local at this time are the following :

["SS", "BS", "B", "S", "NS", "N"]

You can try some alternatives like:

https://www.npmjs.com/package/dynalite

b-s-d
  • 4,953
  • 2
  • 25
  • 31
  • Thank you! Looking at the list of bugs, DynamoDB Local really seems to be difficult to use for actual testing. I will try dynalite then. – AlexanderF Apr 07 '15 at 13:12
  • Please take a look @: http://stackoverflow.com/questions/29525469/how-do-i-enable-dynamodb-local-logging/29525470#29525470 – b-s-d Apr 08 '15 at 21:15