If I have a table with a hash key of userId and a range key of productId how do I put an item into that table only if it doesn't already exist using boto3's dynamodb bindings?
The normal call to put_item looks like this
table.put_item(Item={'userId': 1, 'productId': 2})
My call with a ConditionExpression looks like this:
table.put_item(
Item={'userId': 1, 'productId': 2},
ConditionExpression='userId <> :uid AND productId <> :pid',
ExpressionAttributeValues={':uid': 1, ':pid': 3}
)
But this raises a ConditionalCheckFailedException every time. Whether an item exists with the same productId or not.