我正在尝试使用coveritlive聊天系统创建虚假的受众应用。为此,我创建了不同的lambda函数,一个用于发布评论,一个用于获取项目ID,另一个用于添加评论回复。 但是,为了实现回复服务,我需要获取注释的item_id,可以通过调用coveritlive.com的事件/数据API来获取它。 但是在Amazon DynamoDB中执行更新操作时出现以下异常。我不知道为什么显示此异常。我也想知道是否有可用的批量更新功能。请帮助我解决此问题。
ConditionalCheckFailedException: The conditional request failed at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/json.js:48:27) at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:105:20) at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:
06179d64-8906-11e8-bc53-f1cb2c5efa4e { ConditionalCheckFailedException: The conditional request failed
at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/json.js:48:27)
at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/request.js:685:12)
at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
message: 'The conditional request failed',
code: 'ConditionalCheckFailedException',
requestId: 'JVQV9VI69F3T2UDG6388RLDPFBVV4KQNSO5AEMVJF66Q9ASUAAJG',
statusCode: 400,
retryable: false,
retryDelay: 4.294909454040329
这是我用于更新的代码:
function updateItemId(id,itemId,docClient) {
var updateParams = {
TableName:"comments",
Key: {
Id : Number(id)
},
UpdateExpression: "set ItemId = :ItemId",
ConditionExpression: "ItemId = :x",
ExpressionAttributeValues:{
":ItemId":Number(itemId),
":x":0
},
ReturnValues:"UPDATED_NEW"
};
docClient.update(updateParams,function(err,data){
if(err) {
console.log(err);
}
else{
console.log(data);
}
});
}
我试图通过频繁调用来替换ItemId。
答案 0 :(得分:0)
这很正常,原因是匹配密钥的项中的“ ItemId”不等于0,您要做的就是捕获并忽略它。
if (err.code === 'ConditionalCheckFailedException') {
// nerver mind.
}