DynamoDB 不支持 PutItem 请求中的条件表达式
我正在尝试有条件地将项目写入 DynamoDB 表。
我正在使用 适用于 Java 2.x 的 AWS 开发工具包。下面是我的代码:
PutItemEnhancedRequest<AssessmentBean> putItemRequest =
PutItemEnhancedRequest.builder(AssessmentBean.class)
.conditionExpression(sqsMsgIdNoMatch)
.item(assessment)
.build();
WriteBatch batch =
WriteBatch.builder(AssessmentBean.class)
.addPutItem(putItemRequest)
.mappedTableResource(table)
.build(); // This line throws the IllegalArgumentException
BatchWriteItemEnhancedRequest batchWriteRequest =
BatchWriteItemEnhancedRequest.builder().addWriteBatch(batch).build();
eDDBClient
.batchWriteItem(batchWriteRequest)
.whenCompleteAsync(/* not important to this question */);
如上面代码中的注释所示,我的代码抛出一个 IllegalArgumentException
:
java.lang.IllegalArgumentException:映射器扩展将条件表达式插入 PutItem 请求中,作为 BatchWriteItemRequest 的一部分。 DynamoDb 不支持此功能。已知执行此操作的扩展是 VersionedRecordExtension,除非被覆盖,否则默认情况下会加载该扩展。要解决此问题,请使用其中没有版本化属性的表架构,或者不加载有问题的扩展。
以下是一些类型信息:
putItemRequest
是一个software.amazon.awssdk.enhanced.dynamodb.model.PutItemEnhancedRequest
对象batch
是一个software.amazon.awssdk.enhanced.dynamodb.model.WriteBatch
对象batchWriteRequest
是一个software.amazon.awssdk.enhanced.dynamodb.model.BatchWriteItemEnhancedRequest
对象eDDBClient
是software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedAsyncClient
对象
如何有条件地将项目正确写入 DynamoDB?
I am trying to conditionally write an item to a DynamoDB table.
I am using AWS SDK for Java 2.x. Below is my code:
PutItemEnhancedRequest<AssessmentBean> putItemRequest =
PutItemEnhancedRequest.builder(AssessmentBean.class)
.conditionExpression(sqsMsgIdNoMatch)
.item(assessment)
.build();
WriteBatch batch =
WriteBatch.builder(AssessmentBean.class)
.addPutItem(putItemRequest)
.mappedTableResource(table)
.build(); // This line throws the IllegalArgumentException
BatchWriteItemEnhancedRequest batchWriteRequest =
BatchWriteItemEnhancedRequest.builder().addWriteBatch(batch).build();
eDDBClient
.batchWriteItem(batchWriteRequest)
.whenCompleteAsync(/* not important to this question */);
As indicated by the comment in the code above, my code throws an IllegalArgumentException
:
java.lang.IllegalArgumentException: A mapper extension inserted a conditionExpression in a PutItem request as part of a BatchWriteItemRequest. This is not supported by DynamoDb. An extension known to do this is the VersionedRecordExtension which is loaded by default unless overridden. To fix this use a table schema that does not have a versioned attribute in it or do not load the offending extension.
Below is some type information:
putItemRequest
is asoftware.amazon.awssdk.enhanced.dynamodb.model.PutItemEnhancedRequest
objectbatch
is asoftware.amazon.awssdk.enhanced.dynamodb.model.WriteBatch
objectbatchWriteRequest
is asoftware.amazon.awssdk.enhanced.dynamodb.model.BatchWriteItemEnhancedRequest
objecteDDBClient
is asoftware.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedAsyncClient
object
How do correctly conditionally write an item to DynamoDB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论