/
DescribeTable.java
executable file
·86 lines (73 loc) · 3.51 KB
/
DescribeTable.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package com.example.dynamodb;
// snippet-start:[dynamodb.java2.describe_table.main]
// snippet-start:[dynamodb.java2.describe_table.import]
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.dynamodb.model.DynamoDbException;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition;
import software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest;
import software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughputDescription;
import software.amazon.awssdk.services.dynamodb.model.TableDescription;
import java.util.List;
// snippet-end:[dynamodb.java2.describe_table.import]
/**
* Before running this Java V2 code example, set up your development
* environment, including your credentials.
*
* For more information, see the following documentation topic:
*
* https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html
*/
public class DescribeTable {
public static void main(String[] args) {
final String usage = """
Usage:
<tableName>
Where:
tableName - The Amazon DynamoDB table to get information about (for example, Music3).
""";
if (args.length != 1) {
System.out.println(usage);
System.exit(1);
}
String tableName = args[0];
System.out.format("Getting description for %s\n\n", tableName);
Region region = Region.US_EAST_1;
DynamoDbClient ddb = DynamoDbClient.builder()
.region(region)
.build();
describeDymamoDBTable(ddb, tableName);
ddb.close();
}
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());
System.out.format("Size (bytes): %d\n", tableInfo.tableSizeBytes());
ProvisionedThroughputDescription throughputInfo = tableInfo.provisionedThroughput();
System.out.println("Throughput");
System.out.format(" Read Capacity : %d\n", throughputInfo.readCapacityUnits());
System.out.format(" Write Capacity: %d\n", throughputInfo.writeCapacityUnits());
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!");
}
}
// snippet-end:[dynamodb.java2.describe_table.main]