Search code examples
goamazon-dynamodbunix-timestamp

DynamoDB UpdateItem failed


I am using DynamoDB Go SDK for CRUD operations. I verified PutItem and GetItem calls are working fine. However, when I use UpdateItem which updates some attributes, it fails. I narrowed it down to specific to an attribute that stores the current timestamp in epoch format.

    updateItem := &dynamodb.UpdateItemInput{
        TableName:aws.String(tableName),
        ExpressionAttributeValues: map[string]*dynamodb.AttributeValue{
            ":r": {
                S:aws.String("Renamed"),
            },
            ":rp": {
                S: aws.String("RenamingParty"),
            },
            ":rr": {
                S: aws.String("RenameReason"),
            },
            "rt": {
                N: aws.String(strconv.FormatInt(time.Now().Unix(), 10)),
            },
        },
        Key: map[string]*dynamodb.AttributeValue{
            "pKey": {
                S: aws.String(pKey),
            },
            "rKey": {
                S:aws.String(rKey),
            },
        },
        ReturnValues:aws.String("ALL_NEW"),
        UpdateExpression:aws.String("set RenameStatus = :r, RenamingParty = :rp, RenameReason = :rr RenameTime = :rt"),
    }

    _, err := svc.UpdateItem(updateItem)

Error returned:

failed to update item: %v ValidationException: ExpressionAttributeValues contains invalid key: Syntax error; key: "rt" status code: 400, request id:


Solution

  • It seems like your attribute rt is missing a : -> :rt :)