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

Retrieving items from the DynamoDB table using the object persistence model in .Net


Now, we will see how to use the object persistence model in .Net to get the data from DynamoDB.

Getting ready

To perform this recipe, you should have set up the project, as described in the earlier recipes, specifically, pom.xml, dependencies, and the object model.

How to do it…

  1. Create an instance of AmazonDynamoDBClient and instantiate the DynamoDBContext class, which will be the entry point to DynamoDB:

    AmazonDynamoDBClient client = new AmazonDynamoDBClient();
    DynamoDBContext context = new DynamoDBContext(client);
  2. Invoke the load method from the DynamoDBContext class, specifying the keys of a DynamoDB item that you wish to retrieve:

    Product productRetrieved = context.Load<Product>(111, "book");

How it works…

The AWS SDK internally calls the HTTP APIs to perform the operations. The load method retrieves the data from DynamoDB and puts it into the object that we created. To retrieve a specific attribute of the...