Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB DeleteItem apparently not working - no error given

I'm using put and get without problems, but when it comes to delete, nothing happens. Here's my code:

async function resetUserIdDB(userId) {
  let params = {
    TableName: 'TableName',
    "Key": {
      "userId": {
        "S": userId.toString()
      }
    }
  };
  try {
    const dbResponse = await ddb.deleteItem(params).promise();
    console.log(`dbresponse has params of ${JSON.stringify(params)} and response of ${JSON.stringify(dbResponse)}`);
    if (dbResponse.Item) {
      console.log(`deleted row with userId of ${userId}`);
      return (dbResponse);
    }
  } catch (err) {
      console.log(`user reset failed with ${err}`);
    throw new Error(`failed to reset because of ${err}`);
  }
}

The params all look fine, but I just get an empty response, and no error, but no deletion either. I'm using the same .promise() on all my other dynamodb actions.

Any ideas?

like image 699
digitaltoast Avatar asked Oct 19 '25 11:10

digitaltoast


1 Answers

I just ran into the same problem. It seems like some of the SDK functions don't actually work unless you pass them a callback parameter, even though it's optional. Even a function that does nothing seems to make it work. i.e.

const dbResponse = await ddb.deleteItem(params, () => {}).promise();
like image 93
Ferruccio Avatar answered Oct 21 '25 02:10

Ferruccio