0
boto.dynamodb2.exceptions.ValidationException: ValidationException: 400 Bad Request
{'__type': 'com.amazon.coral.validate#ValidationException', 'message': 'One or more parameter values were invalid: Type mismatch for key restoreid expected: S actual: M'}

I have a simple table test with id

All i am trying to do in insert id into the table with String data type. Primary partition key is id(string)

 table = Table("test")
 stringjson="{\"id\": {\"S\": \"4343\"}}"
 item_data = json.loads(stringjson)

 table.put_item(data=item_data)

I get the error mentioned above. Any suggestions?

Arpan Solanki
  • 817
  • 1
  • 17
  • 28

2 Answers2

0

I think you are using a wrong syntax

look at http://docs.aws.amazon.com/amazondynamodb/latest/gettingstartedguide/GettingStarted.Python.03.html#GettingStarted.Python.03.01

you should try something like:

response = table.put_item(
   Item={
        'id': '4343',
    }
)
Eyal Ch
  • 9,552
  • 5
  • 44
  • 54
0

The Hash Key of a table in DynamoDB can't be MAP. You have a table test defined with hash key id as String. The error says that the key should be String. Also, no need to specify like this. You can just provide the value in double quotes for String.

{\"S\": \"4343\"}

Sample code to add MAP data type:-

"quid" - is the hash key of the table defined as String

"info" - is added as MAP in DynamoDB table

jsonString = {"quid": "102",  "info": { "plot": "Nothing happens at all.", "rating": "AA"} }

response = table.put_item(
   Item=jsonString
)

Output:-

Please refer the below screenshot. The "info" attribute has been added as MAP in DynamoDB table.

enter image description here

notionquest
  • 37,595
  • 6
  • 111
  • 105