madu
madu

Reputation: 5460

Updating a list in DynamoDB

I have tried a number of solutions give here in SO but having trouble with one validation error: This is my table:

var params = {
    AttributeDefinitions: [
        {
            AttributeName: 'USER_AUTH_ID',
            AttributeType: 'N'
        },
        {
            AttributeName: 'EMAIL',
            AttributeType: 'S'
        }
    ],
    KeySchema: [
        {
            AttributeName: 'EMAIL',
            KeyType: 'HASH'
        },
        {
            AttributeName: 'USER_AUTH_ID',
            KeyType: 'RANGE'
        }
    ],
    ProvisionedThroughput: {
        ReadCapacityUnits: 1,
        WriteCapacityUnits: 1
    },
    TableName: tableName,
    StreamSpecification: {
        StreamEnabled: false
    }
};

I have successfully created items using putItem, but having trouble appending to a list:

This is my item to update:

var paramUpdateItem = {
    TableName: tableName,
    Key: {
        'EMAIL' : {S: 'MyEmail@email.com'}
    },
    UpdateExpression: "SET #Y = list_append(#Y,:y)",
    ExpressionAttributeNames: {
        "#Y" : "COMMENT_HISTORY"
    },
    ExpressionAttributeValues: {
        ":y" : [commentToAdd]
    }
}

;

And I update with updateItem.

I keep getting this error:

null: Error: Unexpected key '0' found in params.ExpressionAttributeValues[':y']

I read in another question this is due to tabs, but I have tried to fix it but still getting this error.

Any help. Thank you.

Upvotes: 1

Views: 225

Answers (1)

Nadav Har'El
Nadav Har'El

Reputation: 13791

I cant think of two options. One is that this is a library bug, as you said it might be "due to tabs", see for example this issue claiming that this is a bug with whitespace and suggesting workarounds:

https://github.com/aws/aws-sdk-js/issues/2546

Another option is that you are using the low-level API (you didn't show how you made the query). In the low-level API, you can't just say {":y" : [commentToAdd]}. You need to say that this list is, in fact, a list, and what are the types of its components. Something like {':y': {'L': [{'S', 'word1'}, {'S', 'word2'} ] }.

Upvotes: 3

Related Questions