2

here is the image of data in dynamodb

i want to delete the element from the favRest and i will have to give the value only and it sould do that here is my lambda function

var AWS = require('aws-sdk');

const docClient = new AWS.DynamoDB.DocumentClient({ region: 'us-east-1' });

exports.handler = (event, context, callback) => {
    const params = {
        TableName : 'User',
        Key:{
            "id": event.user_id,
        },
        UpdateExpression: "DELETE favRest :p",
        ExpressionAttributeValues: {
            ':p': event.place_id
        },
        ReturnValues: "ALL_NEW" 
    }

    // TODO: Implementation...

    docClient.update(params, (err, data) => {
        if (err) {
            console.log("Unable to update item. Error: " + err.message);
            callback(err);
        } else {
            console.log("UpdateItem succeeded.");
            callback(null, data);
        }
    });
};

However, it's giving me the following error:

"{\n  \"message\": \"Invalid UpdateExpression: Incorrect operand type for operator or function; operator: DELETE, operand type: STRING\",\n  \"code\": \"ValidationException\",\n  \"time\": \"2018-04-29T18:49:58.628Z\",\n  \"requestId\": \"7TDRI4TOF9S71OUJDEKMIOA40RVV4KQNSO5AEMVJF66Q9ASUAAJG\",\n  \"statusCode\": 400,\n  \"retryable\": false,\n  \"retryDelay\": 35.34160854636804\n}"

what should i have to do

1 Answer 1

2

The DELETE action only supports Set data types. Your favRest attribute type is List.

If you want to keep your favRest attribute type as List, you could either use REMOVE to delete individual elements from the list (knowing the index of the element):

UpdateExpression: "REMOVE favRest[:index]"

or you could use SET to replace the whole list with new values:

UpdateExpression: "SET favRest = :newList"

Otherwise, you could change favRest attribute type to Set.

See Update Expressions.

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.