0
0
DynamoDBquery~5 mins

DeleteItem in DynamoDB

Choose your learning style9 modes available
Introduction

DeleteItem lets you remove a single item from a DynamoDB table. It helps keep your data clean by deleting things you no longer need.

You want to remove a user's old session data after they log out.
You need to delete a product from your inventory when it is discontinued.
You want to clear a temporary record after processing it.
You want to remove a specific comment from a post.
You want to delete a booking that was canceled.
Syntax
DynamoDB
DeleteItem {
  TableName: "YourTableName",
  Key: {
    "PrimaryKeyName": { "S": "PrimaryKeyValue" }
  }
}

The TableName is the name of your DynamoDB table.

The Key specifies which item to delete using its primary key.

Examples
Deletes the user with UserId '123' from the Users table.
DynamoDB
DeleteItem {
  TableName: "Users",
  Key: {
    "UserId": { "S": "123" }
  }
}
Deletes the product with ProductId 'A1B2C3' from the Products table.
DynamoDB
DeleteItem {
  TableName: "Products",
  Key: {
    "ProductId": { "S": "A1B2C3" }
  }
}
Sample Program

This command deletes the book with the ISBN '978-3-16-148410-0' from the Books table.

DynamoDB
DeleteItem {
  TableName: "Books",
  Key: {
    "ISBN": { "S": "978-3-16-148410-0" }
  }
}
OutputSuccess
Important Notes

If the item does not exist, DeleteItem does nothing and returns success.

You can use ReturnValues to get the deleted item's attributes if needed.

Summary

DeleteItem removes one item from a DynamoDB table using its primary key.

It is useful for cleaning up or removing specific records.

The operation is simple and fast, and does nothing if the item is not found.