0

I have a code which is updating an existing AWS DynamoDb item,
I am using the update method of the AWS DynamoDb SDK,
I am getting an error while updating the item -

{ ValidationException: ExpressionAttributeValues contains invalid key: Syntax error; key: "tamt"
message: 'ExpressionAttributeValues contains invalid key: Syntax error; key: "tamt"',
  code: 'ValidationException',
  statusCode: 400,
  retryable: false,

Following is my code -

module.exports.updateCart = async (constants, connection, requestBody) => {
    let table = constants.tables.user_cart;

    let params = {
        TableName: table,
        Key:{
            "cart_id": requestBody.cart_id
        },
        UpdateExpression: "set currency = :curr, product_type = :ptype, total_amount = :tamt,"
        +"total_quantity = :tqty, created_date = :cdate, expiry = :exp, items = :items",
        ExpressionAttributeValues:{
            "curr": requestBody.currency,
            "ptype": requestBody.product_type,
            "tamt": requestBody.total_amount,
            "tqty": requestBody.total_quantity,
            "cdate": requestBody.created_date,
            "exp": requestBody.expiry,
            "items" : requestBody.items
        },
        ReturnValues:"UPDATED_NEW"
    };
    console.log("Params => \n", params);

    let update = util.promisify(connection.update).bind(connection);
    let results = await update(params);
    return results;
}

Following is the console log of Params -

{
    TableName: 'someTable',
    Key: {
        cart_id: 'someId'
    },
    UpdateExpression: 'set currency = :curr, product_type = :ptype, total_amount = :tamt, total_quantity = :tqty, created_date = :cdate, expiry = :exp, items = :items',
    ExpressionAttributeValues: {
        curr: 'USD',
        ptype: 'SPECIAL',
        tamt: 50,
        tqty: 1,
        cdate: 1558499016,
        exp: 1558499016,
        items: items: [{
            name: 'someName',
            amount: 50,
            quantity: 1,
            category: 'some Category'
        }]
    },
    ReturnValues: 'UPDATED_NEW'
}

RequestBody -

{
    product_type: 'SPECIAL',
    user_id: 1234,
    total_amount: 50,
    total_quantity: 1,
    currency: 'USD',
    items: [{
        name: 'someName',
        amount: 50,
        quantity: 1,
        category: 'some Category'
    }],
    created_date: 1558499016,
    expiry: 1558499016,
    cart_id: 'someId'
}

I double checked, total_amount field on the table is of Number type,
What could be the issue?

Ref -
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.NodeJs.03.html#GettingStarted.NodeJs.03.03

1 Answer 1

1

the keys in ExpressionAttributeValues should start with a :

ExpressionAttributeValues:{
        ":curr": requestBody.currency,
        ":ptype": requestBody.product_type,
        ":tamt": requestBody.total_amount,
        ":tqty": requestBody.total_quantity,
        ":cdate": requestBody.created_date,
        ":exp": requestBody.expiry,
        ":items" : requestBody.items
    },
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.