Java Code Examples for com.amazonaws.services.dynamodbv2.AmazonDynamoDB#listTables()
The following examples show how to use
com.amazonaws.services.dynamodbv2.AmazonDynamoDB#listTables() .
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: SpringLocalstackDockerRunnerTest.java From spring-localstack with Apache License 2.0 | 6 votes |
@Test public void testDynamo() throws Exception { AmazonDynamoDB dynamoDB = amazonDockerClientsHolder.amazonDynamoDB(); ListTablesResult tablesResult = dynamoDB.listTables(); assertThat(tablesResult.getTableNames().size(), is(0)); CreateTableRequest createTableRequest = new CreateTableRequest() .withTableName("test.table") .withKeySchema(new KeySchemaElement("identifier", KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition("identifier", ScalarAttributeType.S)) .withProvisionedThroughput(new ProvisionedThroughput(10L, 10L)); dynamoDB.createTable(createTableRequest); tablesResult = dynamoDB.listTables(); assertThat(tablesResult.getTableNames(), hasItem("test.table")); }
Example 2
Source File: DynamoDBEmbeddedTest.java From aws-dynamodb-examples with Apache License 2.0 | 6 votes |
@Test public void createTableTest() { AmazonDynamoDB ddb = DynamoDBEmbedded.create().amazonDynamoDB(); try { String tableName = "Movies"; String hashKeyName = "film_id"; CreateTableResult res = createTable(ddb, tableName, hashKeyName); TableDescription tableDesc = res.getTableDescription(); assertEquals(tableName, tableDesc.getTableName()); assertEquals("[{AttributeName: " + hashKeyName + ",KeyType: HASH}]", tableDesc.getKeySchema().toString()); assertEquals("[{AttributeName: " + hashKeyName + ",AttributeType: S}]", tableDesc.getAttributeDefinitions().toString()); assertEquals(Long.valueOf(1000L), tableDesc.getProvisionedThroughput().getReadCapacityUnits()); assertEquals(Long.valueOf(1000L), tableDesc.getProvisionedThroughput().getWriteCapacityUnits()); assertEquals("ACTIVE", tableDesc.getTableStatus()); assertEquals("arn:aws:dynamodb:ddblocal:000000000000:table/Movies", tableDesc.getTableArn()); ListTablesResult tables = ddb.listTables(); assertEquals(1, tables.getTableNames().size()); } finally { ddb.shutdown(); } }
Example 3
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 4 votes |
/** * 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 4
Source File: ListTables.java From aws-doc-sdk-examples with Apache License 2.0 | 4 votes |
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!"); }