I am using DynamoDBDocument library as:
import { DynamoDBDocument } from "@aws-sdk/lib-dynamodb";
export class DdbConector {
ddbDoc: DynamoDBDocument;
constructor(ddbClient: DynamoDBDocument) {
this.ddbDoc = ddbClient;
}
async deleteItem(TableName: string, id: string): Promise<void> {
const res = await this.ddbDoc.delete( { TableName, Key: {id} } )
console.log(res) // shared the response below
}
}
With this implementation, I am expecting to find out if the delete() request was successful or not. Here is the output of the response:
This is the successful scenario's response. That means the item is deleted from DynamoDB:
{
'$metadata': {
httpStatusCode: 200,
requestId: 'c7a1e277-dc3e-40a1-9122-ad580484b56d',
extendedRequestId: undefined,
cfId: undefined,
attempts: 1,
totalRetryDelay: 0
},
Attributes: undefined,
ConsumedCapacity: undefined,
ItemCollectionMetrics: undefined
}
And this is an unsuccessful scenario response. In this scenario, the Item is not found in DynamoDB:
{
'$metadata': {
httpStatusCode: 200,
requestId: '3fdd38b8-e7e2-4bfe-9541-7f0aab49d6b6',
extendedRequestId: undefined,
cfId: undefined,
attempts: 1,
totalRetryDelay: 0
},
Attributes: undefined,
ConsumedCapacity: {
CapacityUnits: 1,
GlobalSecondaryIndexes: undefined,
LocalSecondaryIndexes: undefined,
ReadCapacityUnits: undefined,
Table: undefined,
TableName: 'Customers',
WriteCapacityUnits: undefined
},
ItemCollectionMetrics: undefined
}
I want to implement the delete operation on DynamoDB. But since DynamoDB response does not show success or failure, I have to get the item for the second time to see if the delete() function succeeded or not. Any suggestions for fixing this properly?