键上的条件数无效-使用DynamoDBMapper更新dynamo项时出错



我是dynamo db的新手。我正在尝试使用以下表达式更新dynamo项目amt属性。

TransactionWriteRequest transactionWriteRequest = new TransactionWriteRequest();
HashMap<String, AttributeValue> attributeValues = new HashMap<>();
attributeValues.put(":amount",  new AttributeValue().withN(amount));
// key
Map<String, AttributeValue> key = new HashMap<>();
key.put("pk", new AttributeValue().withS(pk));
key.put("sk", new AttributeValue().withS(sk));
UpdateItemRequest updateItemRequest = new UpdateItemRequest()
.withKey(key)
.withTableName("dynamo-test")
.withUpdateExpression("SET amt = amt + :amount")
.withExpressionAttributeValues(attributeValues);
transactionWriteRequest.addUpdate(updateItemRequest);
dynamoDBMapper.transactionWrite(transactionWriteRequest);

事务中有多个正在执行的更新。在执行此操作时,它抛出以下异常:

AmazonDynamoDBException: The number of conditions on the keys is invalid

我被困在这里,没有在上面的代码中发现任何错误。请帮忙。

Thanks in advance

我相信你搞砸了两个客户端,如果你不把数据映射到一个类对象,你不应该使用Mapper Client。使用您实例化的DynamoDB底层客户端来发出事务请求。

此外,确保表dynamo-test的分区键pk和排序键sk都是String类型。

最新更新