I am facing a challenge with deleting multiple items from a DynamoDB table. While the documentation suggests dropping and recreating the whole table, I want to avoid this approach as my table was created using AWS Amplify and I don't want to risk disrupting other components in my stack.
After exploring the DynamoDB API and utilizing the aws-sdk
in JavaScript, I have successfully managed to delete single items from the database. However, I am struggling to extend this functionality to delete multiple items at once.
// Delete single item:
import { DeleteItemCommand } from "@aws-sdk/client-dynamodb";
import { ddbClient } from "./dynamoDbClient";
const tableName = "myTableName";
const itemId = "12f10644-546c-45f4-8309-c208061e9737";
export async function deleteItemDynamoDb() {
const command = new DeleteItemCommand({
TableName: tableName,
Key: {
id: {
S: "12f10644-546c-45f4-8309-c208061e9737",
},
},
});
const response = await ddbClient.send(command);
}