在 dynamodb table 上使用 put_item 时收到错误 'The provided key element does not match the schema'
Receiving error 'The provided key element does not match the schema' while using put_item on dynamodb table
我的代码在这里:
try:
with table.batch_writer() as batch:
for i in range(len(rows)):
print(int(rows[i]['cust_id']))
print(int(rows[i]['prdct_id']))
batch.put_item(
Item={
'cust_id': {'N':rows[i]['cust_id']},
'prdct_id': {'N':rows[i]['prdct_id']}
}
)
except Exception as e:
print(e)
我在 table 上将 cust_id 定义为分区键。有人可以帮忙吗?
我发现了问题。题中写的格式是“dynamodb”格式。这基本上意味着它用类型注释(令人讨厌)。这是创建表格所必需的,但 batch_write 需要 json 格式。它应该是这样的:
try:
with table.batch_writer() as batch:
for i in range(len(rows)):
batch.put_item(
Item={
"cust_id": int(rows[i]['cust_id']),
"prdct_id": rows[i]['prdct_id']
}
)
except Exception as e:
print(e)
我的代码在这里:
try:
with table.batch_writer() as batch:
for i in range(len(rows)):
print(int(rows[i]['cust_id']))
print(int(rows[i]['prdct_id']))
batch.put_item(
Item={
'cust_id': {'N':rows[i]['cust_id']},
'prdct_id': {'N':rows[i]['prdct_id']}
}
)
except Exception as e:
print(e)
我在 table 上将 cust_id 定义为分区键。有人可以帮忙吗?
我发现了问题。题中写的格式是“dynamodb”格式。这基本上意味着它用类型注释(令人讨厌)。这是创建表格所必需的,但 batch_write 需要 json 格式。它应该是这样的:
try:
with table.batch_writer() as batch:
for i in range(len(rows)):
batch.put_item(
Item={
"cust_id": int(rows[i]['cust_id']),
"prdct_id": rows[i]['prdct_id']
}
)
except Exception as e:
print(e)