Now, let's understand how to delete a DynamoDB table using the AWS SDK for Java.
In this recipe, we will learn how to delete the table that we created earlier using the AWS SDK for Java:
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");
Now, call the
delete
method of thetable
class to delete the table:table.delete();
Like create and update, delete also takes some time. So, it's good practice to wait until delete takes place on DynamoDB:
table.waitForDelete();