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 bindi
You dont need the sortkey( or range key) just the partition key or hash key is enough.
try:
table.put_item(
Item={
'foo':1,
'bar':2,
},
ConditionExpression='attribute_not_exists(foo)'
)
except botocore.exceptions.ClientError as e:
# Ignore the ConditionalCheckFailedException, bubble up
# other exceptions.
if e.response['Error']['Code'] != 'ConditionalCheckFailedException':
raise