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 Java


Now, we are going to see how to get items from the table using the object persistence model.

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…

Let's use the object persistence model to retrieve the items:

  1. Create an instance of the DynamoDB client class and initiate it with the credential's profile. You can also set the region if you have created the table in a specific region:

    AmazonDynamoDBClient client = new AmazonDynamoDBClient(
        new ProfileCredentialsProvider());
      client.setRegion(Region.getRegion(Regions.US_EAST_1));
  2. Create an instance of the DynamoDBMapper class and initiate it with the client that we created earlier:

    DynamoDBMapper mapper = new DynamoDBMapper(client);
  3. Now, invoke the load method, specifying the keys of the item that you wish to retrieve, and it will fetch...