Deleting an item from the DynamoDB table using the AWS SDK for .Net
Let's understand how to delete an item from the DynamoDB table using the AWS SDK for .Net.
Getting ready
To perform this operation, you can use the IDE of your choice.
How to do it…
Let's try to understand how to delete a stored item from the DynamoDB table using .Net:
Create an instance of the
DynamoDBClientclass:AmazonDynamoDBClient client = new AmazonDynamoDBClient(); string tableName = "productTable";
Create a
deletetable request and specify the key of the item that you wish to delete from the table. Here, we will specify both thehashandrangekeys, as we have created a table with the compositeprimarykeys:var request = new DeleteItemRequest { TableName = tableName, Key = new Dictionary<string,AttributeValue>() { { "id", new AttributeValue { N = "20" } }, { "type", new AttributeValue { S = "phone" }} } };Invoke the
DeleteItemmethod specifying the request:var response = client.DeleteItem(request);