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

Listing tables using the AWS SDK for Java


Now, let's understand how to list all the DynamoDB tables using the AWS SDK for Java.

Getting ready

You can use the IDE of your choice to code these recipes.

How to do it…

In this recipe, we will learn how to list the tables that we created earlier using the AWS SDK for Java:

  1. Create an instance of the DynamoDB class and instantiate it with the AWS credential provider:

    DynamoDB dynamoDB = new DynamoDB(new AmazonDynamoDBClient(
        new ProfileCredentialsProvider()));
  2. Invoke the listTables method of the DynamoDB class to get a list of all the tables:

    TableCollection<ListTablesResult> tables = dynamoDB.listTables();
    Iterator<Table> iterator = tables.iterator();
  3. Now, you can iterate over the list to get the details of the tables you have created:

    while (iterator.hasNext()) {
      Table table = iterator.next();
      System.out.println(table.getTableName());
    }

How it works…

The list table API internally calls DynamoDB services to fetch the details of the tables...