0

How can I pass a variable name in Dynamocdb UpdateExpression, using python.

file is the variable that i want to put in UpdateExpression. When I use like below it gives me

"[ERROR] ClientError: An error occurred (ValidationException) when calling the UpdateItem operation: The document path provided in the update expression is invalid for update

response = table.update_item(
        Key={"runid": item["runid"]},
        UpdateExpression="SET " + file + "= :val1, update_date = :val2",
        ExpressionAttributeValues={
            ":val1": item[file],
            ":val2": item["update_date"],
        }
Neethu Lalitha
  • 3,031
  • 4
  • 35
  • 60

1 Answers1

0

The exception states you're trying to update a nested attribute in a map which does not exist.

For example,

SET mymap['nested_attribute'] = xyz

In this case the attribute mymap does not exist in the item and throww the exception you're seeing.

Refer to this answer for more.

Leeroy Hannigan
  • 11,409
  • 3
  • 14
  • 31