I have a DynamoDB Table and I want a particular value to be updated using multiple condition expression. Can we do that? My code:-
dynamodb = session.resource('dynamodb')
table = dynamodb.Table('gold-images')
response = table.update_item(
Key={
'AccountRegionOS' : AccOs,
'CreationDate' : cred
},
UpdateExpression="set is_active = :r",
ConditionExpression="CreationDate < :num",
ExpressionAttributeValues={
':num' : last_month,
':r': "No"
},
ReturnValues="UPDATED_NEW"
I want Condition expression to be
dynamodb = session.resource('dynamodb')
table = dynamodb.Table('gold-images')
response = table.update_item(
Key={
'AccountRegionOS' : AccOs,
'CreationDate' : cred
},
UpdateExpression="set is_active = :r",
ConditionExpression=("CreationDate < :num") & ("AMIID = :ami"),
ExpressionAttributeValues={
':num' : last_month,
':r': "No",
':ami' : i
},
ReturnValues="UPDATED_NEW"
The condition expression is a string and the logical operators are AND
, OR
and NOT
. So, you'll need to remove outer parentheses and replace &
with AND
:
ConditionExpression = "CreationDate < :num AND AMIID = :ami"
See Condition Expressions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With