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

Querying a Local Secondary Index using the AWS SDK for Java


Now, we are going to see how to query a local secondary index.

Getting ready

To perform this operation, 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 Local 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 = new AmazonDynamoDBClient(
            new ProfileCredentialsProvider());
        client.setRegion(Region.getRegion(Regions.US_EAST_1));
        DynamoDB dynamoDB = new DynamoDB(client);
        Table product = dynamoDB.getTable("product");
  2. Get the index to be queried on:

    Index idMnfrIndex = product.getIndex("IdManufacturerIndex");
  3. Now...