如何将地图插入 DynamoDB 表?

Daw*_*y33 4 python amazon-dynamodb boto3

我有以下代码行:

table.put_item( Item={'filename' : key, 'status' : {'M' : iocheckdict }})
Run Code Online (Sandbox Code Playgroud)

iocheckdict如下所示:

{'A': 'One', 'C': 'Three', 'D': 'Four', 'B': 'Two', 'E': 'Five'}
Run Code Online (Sandbox Code Playgroud)

因此,当我运行代码时,出现此错误:

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
Run Code Online (Sandbox Code Playgroud)

为什么我得到这个,即使我提到M了数据的类型?

PS:我有2列filename,并status在我的表


表的属性定义:

"AttributeDefinitions": [
    {
        "AttributeName": "filename",
        "AttributeType": "S"
    },
    {
        "AttributeName": "status",
        "AttributeType": "S"
    }
],
Run Code Online (Sandbox Code Playgroud)

我知道的类型status是S,但是我在创建表时没有找到地图类型。我发现的只是string,binarynumber

omu*_*thu 7

插入 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)
Run Code Online (Sandbox Code Playgroud)