Querying a Global Secondary Index using the AWS SDK for Java

Now, we are going to see how to query a global secondary index. This will help us fetch the required items as per the query conditions.

Getting ready

To perform this recipe, you can use the IDE of your choice. To perform a query operation, you should first add items using the AWS Console or SDK, as we have seen in the earlier chapters.

How to do it…

The Query API on a Global Secondary Index is similar to the Query API on a DynamoDB table. Perform the following operations in order to query the index:

  1. Create an instance of the DynamoDB class and initialize it with the credentials. Also, get the table from DynamoDB on which you wish to perform the query operation:
     AmazonDynamoDBClient client ...

Get DynamoDB Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.