Invalid attribute value type: ValidationException on DynamoDB Put
The BOOL data type can't be a key attribute (i.e. Partition or Sort key). The Partition or Sort key data type can be of three types (listed below). If you have created the table with Sort key of type 'B', it means that sort key is of type Binary (i.e. not Bool).
EDIT: You can't use a BOOL attribute as the partition or sort key in a GSI as well.
AttributeType: 'S | N | B'
S - the attribute is of type String
N - the attribute is of type Number
B - the attribute is of type Binary
When the table is created with key of type BOOL, the API would throw the below exception.
Unable to create table. Error JSON: {
"message": "Member must satisfy enum value set: [B, N, S]",
"code": "ValidationException",
Tanmay
Updated on June 15, 2022Comments
-
Tanmay almost 2 years
I am trying to do a put item on a Dynamo Table using the nodejs sdk. I tried using the same document and a few other variations but nothing seems to work. Everytime I receive the same error:
"message":"Invalid attribute value type" "code":"ValidationException" "time":"2016-10-11T06:32:26.361Z" "statusCode":400 "retryable":false
The following is the relevant code snippet:
var params = { TableName: "MY_Table_Name", Item: { "stringAtt": "stringValue", "boolAtt": true, "numAtt": 123, }, }; docClient.put(params, function(err, data) { if (err) ppJson(err); // an error occurred else ppJson(data); // successful response });
My table's indexes are as follows:
Primary: Partition Key: stringAtt, Sort Key: boolAtt
GSI: Partition Key: boolAtt, Sort Key: numAttI am not sure if it's my query or the index structure that is wrong.
-
Tanmay over 7 yearsThanks, What is the recommended way to solve this? My requirement is to get all items with the specified boolean value true/false.
-
notionquest over 7 yearsYou have to scan the table to get all items where boolAttribute = true/false.
-
lod over 6 yearsYou can also use a numeric type and just constrain yourself to only using the values 0 and 1. This will cause issues at scale but given your design I doubt that you will be in that range.