AWS Code Sample

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above. demonstrates how to ...

/* Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. This file is licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package com.example.dynamodb; import; import; import; import; import java.util.List; /** * List DynamoDB tables for the current AWS account. * * This code expects that you have AWS credentials set up per: * */ public class ListTables { public static void main(String[] args) { System.out.println("Your DynamoDB tables:\n"); DynamoDbClient ddb = DynamoDbClient.create(); boolean more_tables = true; String last_name = null; while(more_tables) { try { ListTablesResponse response = null; if (last_name == null) { ListTablesRequest request = ListTablesRequest.builder().build(); response = ddb.listTables(request); } else { ListTablesRequest request = ListTablesRequest.builder() .exclusiveStartTableName(last_name).build(); response = ddb.listTables(request); } List<String> table_names = response.tableNames(); if (table_names.size() > 0) { for (String cur_name : table_names) { System.out.format("* %s\n", cur_name); } } else { System.out.println("No tables found!"); System.exit(0); } last_name = response.lastEvaluatedTableName(); if (last_name == null) { more_tables = false; } } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } } System.out.println("\nDone!"); } }

Sample Details

Service: dynamodb

Author: soo-aws

Type: full-example

On this page: