How to prevent creating a new item in UpdateItem if the item does not exist

前端 未结 3 1615
鱼传尺愫
鱼传尺愫 2020-12-29 17:53

I am running an AWS Lambda service written in Node.js that interacts with a DynamoDB database. One of my methods performs an update (AWS.DynamoDB.DocumentClient().update) on

3条回答
  •  余生分开走
    2020-12-29 18:46

    I bumped into a somehow similar problem using attribute_exists, the only difference is, I need to query from the table and get only the record that does have the attribute I need. Using ConditionExpression did not work for me. Thought of sharing it here in case someone is in need.

    Here, if the subscriberKey is equal to given param and the attribute_exists (mobileNumber) within the record, it returns true, false otherwise.

    var params = {
        TableName : table_name,
        IndexName: "subsciberKey-index",
        KeyConditionExpression: "subscriberKey = :subscriberKey",
        FilterExpression: "attribute_exists(mobileNumber)",
        ExpressionAttributeValues: {
            ":subscriberKey": subscriberNo
        }
    };

提交回复
热议问题