Update attribute "timestamp" reserved word

Amazon DynamodbBoto3

Amazon Dynamodb Problem Overview


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",

Amazon Dynamodb Solutions


Solution 1 - Amazon Dynamodb

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCread DotsonView Question on Stackoverflow
Solution 1 - Amazon DynamodbMike DinescuView Answer on Stackoverflow