I need to update the timestamp attribute in my dynamodb table using boto3 but the attribute name "timestamp" is a reserved word so it's throwing an error on the SET command.
table.update_item(
Key={
'id': item_id
},
UpdateExpression='SET timestamp = :val1', # this is the line giving the problem
ExpressionAttributeValues={
":val1": new_timestamp
}
)
"errorMessage": "An error occurred (ValidationException) when calling the UpdateItem operation: Invalid UpdateExpression: Attribute name is a reserved keyword; reserved keyword: timestamp",
You can work around this problem using expression attribute names (similar to the ExpressionAttributeValues you are already using).
table.update_item(
Key={
'id': item_id
},
UpdateExpression='SET #ts = :val1',
ExpressionAttributeValues={
":val1": new_timestamp
},
ExpressionAttributeNames={
"#ts": "timestamp"
}
)
Read all about it here: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html