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

Getting an item from the DynamoDB table using the AWS SDK for .Net


Let's understand how to get 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 retrieve a stored item from the DynamoDB table using .Net:

  1. Create an instance of the DynamoDB client:

    AmazonDynamoDBClient client = new AmazonDynamoDBClient();
    string tableName = "productTable";
  2. Create a GetItemRequest that specifies the primary key details:

    var request = new GetItemRequest
      {
        TableName = tableName,
        Key = new Dictionary<string,AttributeValue>() {
            {"id",new AttributeValue{ N="20"}
        },
        {"type", new AttributeValue{ S="phone"}
        }
    },
    };

    Here, we have a composite primary key as the ID and type.

  3. Invoke the GetItem method with a specified request, and fetch the items from the results:

    var response = client.GetItem(request);
    var result = response.GetItemResult;

How it works…

The API invocations...