Book Image

DynamoDB Cookbook

By : Tanmay Deshpande
Book Image

DynamoDB Cookbook

By: Tanmay Deshpande

Overview of this book

Table of Contents (18 chapters)
DynamoDB Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. Create an instance of the DynamoDBClient class:

    AmazonDynamoDBClient client = new AmazonDynamoDBClient();
    string tableName = "productTable";
  2. Create a delete table request and specify the key of the item that you wish to delete from the table. Here, we will specify both the hash and range keys, as we have created a table with the composite primary keys:

    var request = new DeleteItemRequest
    {
        TableName = tableName,
        Key = new Dictionary<string,AttributeValue>() 
    { 
    { "id", new AttributeValue { N = "20" } },
       { "type", new AttributeValue { S = "phone" }}
    }
    };
  3. Invoke the DeleteItem method specifying the request:

    var response = client.DeleteItem(request);

How...