GerryG
GerryG

Reputation: 41

DeleteItemCommand from aws-sdk/client-dynamodb doesn't work as expected

I've been trying to delete an item from a DynamoDB table, with no success and no actual errors. My delete function is as follows:

public async deleteToken(token: string) {
const input: DeleteItemCommandInput = {
  TableName: this.tableName,
  Key: {
    Token: {
      S: token,
    },
  },
};

// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-dynamodb/classes/deleteitemcommand.html
const command = new DeleteItemCommand(input);


//Send command to DDB
const response = await this.client.send(command);

console.log("response", response);

return response;

}

Although in postman I'm getting a success code, nothing actually happens. The item is still in the table. I have checked and the token value I'm using in the input is the correct one. The weird this is that the response promise never resolves and I'm not getting an error. The console log below "const response = await this.client.send(command);" is ignored.

Any ideas please?

Upvotes: 4

Views: 1347

Answers (1)

Is this Token field acting as a secondary index (GSI) in your Dynamo table? As far as I know you only can apply a delete operation using a primary one, so if Token is a GSI, I would say the easiest way is to do it in two steps:

  1. Use the GSI index to find the item (find by Token).
  2. Use the primary index in the item returned to delete it.

Upvotes: 0

Related Questions