Java Code Examples for com.amazonaws.services.dynamodbv2.model.ListTablesResult#getLastEvaluatedTableName()

The following examples show how to use com.amazonaws.services.dynamodbv2.model.ListTablesResult#getLastEvaluatedTableName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LowLevelTableExample.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
static void listMyTables() {
    String lastEvaluatedTableName = null;
    do {

        ListTablesRequest listTablesRequest = new ListTablesRequest().withLimit(10)
            .withExclusiveStartTableName(lastEvaluatedTableName);

        ListTablesResult result = client.listTables(listTablesRequest);
        lastEvaluatedTableName = result.getLastEvaluatedTableName();

        for (String name : result.getTableNames()) {
            System.out.println(name);
        }

    } while (lastEvaluatedTableName != null);
}
 
Example 2
Source File: LowLevelTableExample.java    From aws-dynamodb-examples with Apache License 2.0 6 votes vote down vote up
static void listMyTables() {
    String lastEvaluatedTableName = null;
    do {
        
        ListTablesRequest listTablesRequest = new ListTablesRequest()
        .withLimit(10)
        .withExclusiveStartTableName(lastEvaluatedTableName);
        
        ListTablesResult result = client.listTables(listTablesRequest);
        lastEvaluatedTableName = result.getLastEvaluatedTableName();
        
        for (String name : result.getTableNames()) {
            System.out.println(name);
        }
        
    } while (lastEvaluatedTableName != null);
}
 
Example 3
Source File: DynamoDBTableResolver.java    From aws-athena-query-federation with Apache License 2.0 5 votes vote down vote up
private List<String> listTablesInternal()
        throws TimeoutException
{
    List<String> tables = new ArrayList<>();
    String nextToken = null;
    do {
        ListTablesRequest ddbRequest = new ListTablesRequest()
                .withExclusiveStartTableName(nextToken);
        ListTablesResult result = invoker.invoke(() -> ddbClient.listTables(ddbRequest));
        tables.addAll(result.getTableNames());
        nextToken = result.getLastEvaluatedTableName();
    }
    while (nextToken != null);
    return tables;
}
 
Example 4
Source File: ListTablesWorker.java    From dynamodb-janusgraph-storage-backend with Apache License 2.0 5 votes vote down vote up
@Override
public ListTablesResult next() throws BackendException {
    final ListTablesResult result = delegate.listTables(request);
    if (result.getLastEvaluatedTableName() != null && !result.getLastEvaluatedTableName().isEmpty()) {
        request.setExclusiveStartTableName(result.getLastEvaluatedTableName());
    } else { //done
        markComplete();
    }

    // c add scanned items
    tableNames.addAll(result.getTableNames());
    return result;
}
 
Example 5
Source File: InventoryUtil.java    From pacbot with Apache License 2.0 4 votes vote down vote up
/**
 * Fetch dynamo DB tables.
 *
 * @param temporaryCredentials the temporary credentials
 * @param skipRegions the skip regions
 * @param accountId the accountId
 * @param accountName the account name
 * @return the map
 */
public static Map<String,List<DynamoVH>> fetchDynamoDBTables(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){
	Map<String,List<DynamoVH>> dynamodbtables = new LinkedHashMap<>();

	String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"DynamoDB\" , \"region\":\"" ;
	for(Region region : RegionUtils.getRegions()){
		try{
			if(!skipRegions.contains(region.getName())){
				AmazonDynamoDB awsClient= AmazonDynamoDBClientBuilder.standard().
					 withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build();
				String marker = null;
				List<String> tables = new ArrayList<>();
				ListTablesResult listTableResult;
				do{
					listTableResult = awsClient.listTables(new ListTablesRequest().withExclusiveStartTableName(marker));
					marker = listTableResult.getLastEvaluatedTableName();
					tables.addAll(listTableResult.getTableNames());
				}while(marker!=null);

				List<DynamoVH> dynamodbtablesTemp = new ArrayList<>();
				tables.parallelStream().forEach(tblName -> {
					TableDescription table = awsClient.describeTable(tblName).getTable();
					List<com.amazonaws.services.dynamodbv2.model.Tag> tags = awsClient.listTagsOfResource(new ListTagsOfResourceRequest().withResourceArn( table.getTableArn())).getTags();
					synchronized (dynamodbtablesTemp) {
						dynamodbtablesTemp.add(new DynamoVH(table,tags));
					}

				});
				if(!dynamodbtablesTemp.isEmpty() ){
					log.debug(InventoryConstants.ACCOUNT + accountId +" Type : DynamoDB "+region.getName() + " >> "+dynamodbtablesTemp.size());
					dynamodbtables.put(accountId+delimiter+accountName+delimiter+region.getName(), dynamodbtablesTemp);
				}

			}
		}catch(Exception e){
			if(region.isServiceSupported(AmazonDynamoDB.ENDPOINT_PREFIX)){
				log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}");
				ErrorManageUtil.uploadError(accountId,region.getName(),"dynamodb",e.getMessage());
			}
		}
	}
	return dynamodbtables;
}
 
Example 6
Source File: ListTables.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args)
{
    System.out.println("Your DynamoDB tables:\n");

    final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();

    ListTablesRequest request;

    boolean more_tables = true;
    String last_name = null;

    while(more_tables) {
        try {
            if (last_name == null) {
            	request = new ListTablesRequest().withLimit(10);
            }
            else {
            	request = new ListTablesRequest()
            			.withLimit(10)
            			.withExclusiveStartTableName(last_name);
            }

            ListTablesResult table_list = ddb.listTables(request);
            List<String> table_names = table_list.getTableNames();

            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 = table_list.getLastEvaluatedTableName();
            if (last_name == null) {
                more_tables = false;
            }

        } catch (AmazonServiceException e) {
            System.err.println(e.getErrorMessage());
            System.exit(1);
        }
    }
    System.out.println("\nDone!");
}