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

Creating a DynamoDB table with a Local Secondary Index using the AWS SDK for Java


As mentioned earlier, we have seen how to create a table with a global secondary index; now, let's see how to create a table with a local secondary index.

Getting ready

To perform this operation, you can use the IDE of your choice.

How to do it…

To get started, create a maven project, and add the AWS SDK dependency to the POM.xml. Here is the latest version of the AWS SDK for Java:

  1. Create an instance of the DynamoDB class and initialize it with ProfileCredentialsProvider:

    AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider());
        client.setRegion(Region.getRegion(Regions.US_EAST_1));
    DynamoDB dynamoDB = new DynamoDB(client);
  2. Create the attribute definitions we created earlier for the table creation recipe. Here, we will create the table named productTable with the primary key attributes as id and type:

        ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList&lt...