我尝试批量写入dynamo,但目前在Cloudwatch日志中遇到此错误
Supplied AttributeValue has more than one datatypes set, must contain exactly one of the supported datatypes
以批处理方式写入dynamo的逻辑如下
const writeThingsInBatch = async (things: Things[], accountId: string, key: string): Promise<void> => {
if (!tableName) {
throw new Error(DynamoError.InvalidTableName);
}
const putRequests: PutRequest[] = things.map((thing) => ({ Item: enhancedSearchFilterToItem(key, accountId, thing) }));
const putRequestChunks: PutRequest[][] = chunk(putRequests, 25); //lodash
for (const putRequestChunk of putRequestChunks) {
try {
console.log("Request chunk", JSON.stringify(putRequestChunk))
const data = await dynamoClient.send(new BatchWriteCommand({ RequestItems: { tableName: putRequestChunk } }));
console.log("data from batch", { data })
if (data.UnprocessedItems) {
console.warn("Some items have not been processed in BatchWriteCommand", { UnprocessedItems: data.UnprocessedItems });
return;
}
return;
} catch (error) {
console.error("Error when Batch writing to dynamo", { error });
}
}
};
在try
之后,我有一个日志来检查我添加到Request.tableName
中的区块的外观,从那里可以看到数据看起来是正确的
[
{
"Item": {
"key": "d43ecafc-233e-35e2-a7c0-124e833123b3",
"reference": "61498eeaa995ad0073bb8444#0010250",
"code": "numberOfComments = 2",
"allowed": true,
"isSyncable": true,
"syncIt": "1676972136978"
}
},
{
"Item": {
"key": "d43ecafc-233e-35e2-a7c0-124e833123b3",
"reference": "61498eeaa995ad0073bb8444#0010251",
"code": "numberOfComments = 2",
"allowed": true,
"isSyncable": true,
"syncIt": "1676972136978"
}
},
{
"Item": {
"key": "d43ecafc-233e-35e2-a7c0-124e833123b3",
"reference": "61498eeaa995ad0073bb8444#0010252",
"code": "numberOfComments = 2",
"allowed": true,
"isSyncable": true,
"syncIt": "1676972136978"
}
},
{
"Item": {
"key": "d43ecafc-233e-35e2-a7c0-124e833123b3",
"reference": "61498eeaa995ad0073bb8444#0010253",
"code": "numberOfComments = 2",
"allowed": true,
"isSyncable": true,
"syncIt": "1676972136978"
}
},
{
"Item": {
"key": "d43ecafc-233e-35e2-a7c0-124e833123b3",
"reference": "61498eeaa995ad0073bb8444#0010254",
"code": "numberOfComments = 2",
"allowed": true,
"isSyncable": true,
"syncIt": "1676972136978"
}
},
{
"Item": {
"key": "d43ecafc-233e-35e2-a7c0-124e833123b3",
"reference": "61498eeaa995ad0073bb8444#0010255",
"code": "numberOfComments = 2",
"allowed": true,
"isSyncable": true,
"syncIt": "1676972136978"
}
},
{
"Item": {
"key": "d43ecafc-233e-35e2-a7c0-124e833123b3",
"reference": "61498eeaa995ad0073bb8444#0010256",
"code": "numberOfComments = 2",
"allowed": true,
"isSyncable": true,
"syncIt": "1676972136978"
}
},
{
"Item": {
"key": "d43ecafc-233e-35e2-a7c0-124e833123b3",
"reference": "61498eeaa995ad0073bb8444#0010257",
"code": "numberOfComments = 2",
"allowed": true,
"isSyncable": true,
"syncIt": "1676972136978"
}
},
{
"Item": {
"key": "d43ecafc-233e-35e2-a7c0-124e833123b3",
"reference": "61498eeaa995ad0073bb8444#0010258",
"code": "numberOfComments = 2",
"allowed": true,
"isSyncable": true,
"syncIt": "1676972136978"
}
},
]
我已经阅读了一些帖子,到目前为止,人们的错误似乎不是我所做的,除非我错过了一些真正容易的。任何帮助将不胜感激。
1条答案
按热度按时间6vl6ewon1#
发现了这个问题,如果有人福尔斯这个问题,解决方案是在
RequestItems.tableName
数组中包含的每个项中实际包含我们对dynamoPutRequest
发出的请求类型。更新以下代码