Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I insert a map into DynamoDB table?

I have the following line of code :

table.put_item( Item={'filename' : key, 'status' : {'M' : iocheckdict }})

The iocheckdict looks like this:

{'A': 'One', 'C': 'Three', 'D': 'Four', 'B': 'Two', 'E': 'Five'}

So, when I am running the code, I get this error:

An error occurred (ValidationException) when calling the PutItem operation: One or more parameter values were invalid: Type mismatch for key status expected: S actual: M

Why am I getting this, even though I mentioned M as the type of the data?

PS : I have 2 columns filename and status in my table


Attribute definitions of the table:

"AttributeDefinitions": [
    {
        "AttributeName": "filename",
        "AttributeType": "S"
    },
    {
        "AttributeName": "status",
        "AttributeType": "S"
    }
],

I understand that the type of status is S, but I haven't found the map type while creating the table. All I found are string, binary and number.

like image 711
Dawny33 Avatar asked Mar 10 '23 07:03

Dawny33


1 Answers

Easier way to insert into dynamodb

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table("table_name")

item={}
item['filename'] = key
item['status'] = {'A': 'One', 'C': 'Three', 'D': 'Four', 'B': 'Two', 'E': 'Five'}

table.put_item(Item=item)
like image 177
omuthu Avatar answered Mar 21 '23 06:03

omuthu