node.jsamazon-dynamodbaws-sdk-nodejsdocumentclient

Empty data object when deleting item from dynamodb


According to the docs I should get a data structure with the item as it was prior to the deletion (in case there was no error)
I do check there was no error but I get an empty object for data:

    docClient.delete(params, (err, data) => {
    if (err) {
        console.error('Error tring to delete item:' + err);
        callback(err, null); // error
    } else if (!data.Items || data.Items.length == 0) {
        console.info(JSON.stringify(data));
        callback(null, null); // no items
    } else  {
        console.info(JSON.stringify(data));
        callback(null, data.Items[0].ExposeStartTimestamp);
    }
});

Both prints empty json: {}


Solution

  • In order for the deleted data to appear in the response, the request should contain the attribute ReturnValues with value ALL_OLD.

    var params = {
        TableName: 'TableName',
        Key: {
            HouseId: houseId
        },
        ReturnValues: 'ALL_OLD'
    };