Search in sources :

Example 1 with TableDescription

use of software.amazon.awssdk.services.dynamodb.model.TableDescription in project aws-doc-sdk-examples by awsdocs.

the class DescribeTable method describeDymamoDBTable.

// snippet-start:[dynamodb.java2.describe_table.main]
public static void describeDymamoDBTable(DynamoDbClient ddb, String tableName) {
    DescribeTableRequest request = DescribeTableRequest.builder().tableName(tableName).build();
    try {
        TableDescription tableInfo = ddb.describeTable(request).table();
        if (tableInfo != null) {
            System.out.format("Table name  : %s\n", tableInfo.tableName());
            System.out.format("Table ARN   : %s\n", tableInfo.tableArn());
            System.out.format("Status      : %s\n", tableInfo.tableStatus());
            System.out.format("Item count  : %d\n", tableInfo.itemCount().longValue());
            System.out.format("Size (bytes): %d\n", tableInfo.tableSizeBytes().longValue());
            ProvisionedThroughputDescription throughputInfo = tableInfo.provisionedThroughput();
            System.out.println("Throughput");
            System.out.format("  Read Capacity : %d\n", throughputInfo.readCapacityUnits().longValue());
            System.out.format("  Write Capacity: %d\n", throughputInfo.writeCapacityUnits().longValue());
            List<AttributeDefinition> attributes = tableInfo.attributeDefinitions();
            System.out.println("Attributes");
            for (AttributeDefinition a : attributes) {
                System.out.format("  %s (%s)\n", a.attributeName(), a.attributeType());
            }
        }
    } catch (DynamoDbException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    System.out.println("\nDone!");
}
Also used : DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException) AttributeDefinition(software.amazon.awssdk.services.dynamodb.model.AttributeDefinition) DescribeTableRequest(software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest) ProvisionedThroughputDescription(software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughputDescription) TableDescription(software.amazon.awssdk.services.dynamodb.model.TableDescription)

Example 2 with TableDescription

use of software.amazon.awssdk.services.dynamodb.model.TableDescription in project cas by apereo.

the class DynamoDbTableUtils method waitForTableDescription.

private static TableDescription waitForTableDescription(final DynamoDbClient dynamo, final String tableName, final TableStatus desiredStatus, final int timeout, final int interval) throws Exception {
    val startTime = System.currentTimeMillis();
    val endTime = startTime + timeout;
    val tableRequest = DescribeTableRequest.builder().tableName(tableName).build();
    TableDescription table = null;
    while (System.currentTimeMillis() < endTime) {
        try {
            table = dynamo.describeTable(tableRequest).table();
            if (desiredStatus == null || table.tableStatusAsString().equals(desiredStatus.toString())) {
                return table;
            }
        } catch (final ResourceNotFoundException rnfe) {
            LOGGER.trace(rnfe.getMessage());
        }
        Thread.sleep(interval);
    }
    return table;
}
Also used : lombok.val(lombok.val) ResourceNotFoundException(software.amazon.awssdk.services.dynamodb.model.ResourceNotFoundException) TableDescription(software.amazon.awssdk.services.dynamodb.model.TableDescription)

Aggregations

TableDescription (software.amazon.awssdk.services.dynamodb.model.TableDescription)2 lombok.val (lombok.val)1 AttributeDefinition (software.amazon.awssdk.services.dynamodb.model.AttributeDefinition)1 DescribeTableRequest (software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest)1 DynamoDbException (software.amazon.awssdk.services.dynamodb.model.DynamoDbException)1 ProvisionedThroughputDescription (software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughputDescription)1 ResourceNotFoundException (software.amazon.awssdk.services.dynamodb.model.ResourceNotFoundException)1