Can we use DynamoDb optimistic locking with batchWriteItem request? AWS docs on Optimistic locking mention that a ConditionalCheckFailedException is thrown when the version value is different while updating the request. In case of batchWriteItem request, will the whole batch fail or only that record with a different version value? Will the record that failed due to different version value be returned as an unprocessed record?
1 Answer
You cannot. You can be sure by looking at the low level syntax and notice there’s no ability to specify a condition expression.
https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html
2 Comments
Mike Reddington
For optimistic locking we don't need to specify conditional check, DynamoDB will throw this exception if the version number in the write request is not the same as the one stored in db. What I wanted to know is if DynamoDB supports optimistic locking for each individual write item request in the batchWriteItem request or not.
hunterhacker
The Java SDK has to use the conditional expression functionality to achieve that optimistic locking behavior. Since the wire protocol doesn’t support it, Java can’t do it.