Currently this feature is not supported in DynamodbLocal 2.0, and the item returned is null for single write operations (but works for transactions). Is there any plans to add support?
example:
try {
com.amazonaws.services.dynamodbv2.model.PutItemRequest request2 = new com.amazonaws.services.dynamodbv2.model.PutItemRequest()
.withTableName(tableName)
.withItem(Map.of(keyName, new com.amazonaws.services.dynamodbv2.model.AttributeValue(keyValue))) // matches existing document
.withConditionExpression("attribute_exists(#key)")
.withExpressionAttributeNames(Map.of("#key", "non_existing_attribute"))
.withReturnValuesOnConditionCheckFailure("ALL_OLD");
dynamoDB.putItem(request2);
} catch (final ConditionalCheckFailedException e) {
System.out.println("Return value: " + e.getItem()); // returns null
}