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

Deleting a table using the AWS SDK for Java


Now, let's understand how to delete a DynamoDB table 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 delete the table that we created earlier using the AWS SDK for Java:

  1. Initialize the DynamoDB Client and call the getTable method by providing the name of the table that you wish to delete:

    AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider());
    client.setRegion(Region.getRegion(Regions.US_EAST_1));
    DynamoDB dynamoDB = new DynamoDB(client);
    Table table = dynamoDB.getTable("productTableJava");
  2. Now, call the delete method of the table class to delete the table:

    table.delete();
  3. Like create and update, delete also takes some time. So, it's good practice to wait until delete takes place on DynamoDB:

    table.waitForDelete();

How it works…

Once we invoke these APIs, the AWS SDK deletes the table forever. So, I request that you use this...