Dynamodb Update Item Expression with python boto3

17,028

Don't plug the value into the expression directly. Rather use ExpressionAttributeValues -- see boto3 guide

persontable.update_item(Key={'person_id':person_id},
                        UpdateExpression="SET title = :updated",                   
                        ExpressionAttributeValues={':updated': 'UPDATED'})
Share:
17,028
George B
Author by

George B

Updated on June 13, 2022

Comments

  • George B
    George B almost 2 years

    I have a string field, "title". I am trying to update it with the update expression with

    persontable.update_item(Key={'person_id':person_id}, UpdateExpression="SET title = UPDATED")
    

    and I get

    An error occurred (ValidationException) when calling the UpdateItem operation: The provided expression refers to an attribute that does not exist in the item
    

    I can see the attribute "title" for that person in the AWS console. What gives?

  • Willie Cheng
    Willie Cheng almost 8 years
    Please check this URL it will be useful to raise your content quality up