Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS DynamoDB update item using multiple condition expression

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"
like image 841
Praveen Raghav Avatar asked Dec 23 '22 09:12

Praveen Raghav


1 Answers

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.

like image 104
Khalid T. Avatar answered Jan 20 '23 09:01

Khalid T.