0
votes

I'm trying to delete some items from DynamoDB table. My table has a global secondary index. And I'm wondering if it's possible to use the batchWrite method of the DocumentClient to delete items from GSI table. Or we can use GSI for fetching data only?

var params = {
  RequestItems: {
    'Table-1': [
      {
        DeleteRequest: {
          Key: { HashKey: 'someKey' }
        }
      }
    ]
  }
};

documentClient.batchWrite(params, function(err, data) {
  if (err) console.log(err);
  else console.log(data);
});

if it's possible please provide some example of params.

docs

1

1 Answers

0
votes

You cannot delete from a GSI. These indexes are pretty much read only: you can’t mutate the data in the table through a global secondary index, so no inserting, deleting or updating.

You can only read from the GSI and then implement the necessary logic to delete the items in the main table by key.

Also, a batch operation doesn’t make it a whole lot more efficient to delete those items: yes, it saves on network calls (up to 25:1) but not on used write capacity.