8

Trying to do an update_item which is supposed to create new attributes if it doesn't find existing ones (according to documentation) but I am getting a Sytax error.

I have been wracking my brain all day trying to figure out why I am getting this and I can't seem to get past this. Thank you for any help

Error I am getting:

ClientError: An error occurred (ValidationException) when calling the UpdateItem operation:
   ExpressionAttributeValues contains invalid key: Syntax error; key: "var4"

MyCode:

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('contacts')
    table.update_item(
    Key={'email': emailID},
    UpdateExpression=SET last_name = :var0, address_1_state = :var1, email_2 = :var2, phone = :var3, phone_2 = :var4

    ExpressionAttributeValues={
     'var0': 'Metzger', 
     'var1': 'CA', 
     'var2': 'none', 
     'var3': '949 302-9072', 
     'var4': '818-222-2311'
    }
    )
2
  • 3
    did you modify your code section after the answer was posted? the answer code looks identical to the code given in the question... Commented Feb 20, 2021 at 3:36
  • 2
    The change was in the key names. For example from 'var0' to ':var0' (added the two dots) Commented Mar 17, 2021 at 12:35

1 Answer 1

28

just change the section like the following -

 ExpressionAttributeValues={
     ':var0': 'Metzger', 
     ':var1': 'CA', 
     ':var2': 'none', 
     ':var3': '949 302-9072', 
     ':var4': '818-222-2311'
    }

Hope the code will work then :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.