I am referring to this sample of update item: https://stackoverflow.com/a/62030403/13967222.
for key, val in body.items():
update_expression.append(f" {key} = :{key},")
update_values[f":{key}"] = val
return "".join(update_expression)[:-1], update_values
I am trying to achieve the same but using dynamodb client.
Is there way I add check if the value is available using dynamodb client?
You can check if the key attribute already exists passing
ConditionExpressionparameter in the request like that (based on the response in the answer you're referring to):Your write will be executed only when
ConditionExpressionreturnsTrue.attribute_not_existsis a DynamoDb function that returnsTruewhen the specified attribute does not exist. There is also aattribute_existsfunction to achieve the opposite result. More about DDB condition functions in official documentationAlso, you can check the Python example of conditional writes in docs here