使用 java 代码获取在 AWS DynamoDb 中创建的表
Getting tables created in AWS DynamoDb using java code
我在名为 'test' 的 AWS 账户中的 dynamoDb 中创建了一个 table。我正在尝试通过输入我的凭据并使用 Java 代码来列出我帐户中的所有 tables:
static void listAllTables() {
static BasicAWSCredentials awsCreds = new BasicAWSCredentials("AWSAccessKeyId", "AWSSecretKey");
static DynamoDB dynamoDB = new DynamoDB(new AmazonDynamoDBClient(awsCreds));
TableCollection<ListTablesResult> tables = dynamoDB.listTables();
Iterator<Table> iterator = tables.iterator();
System.out.println("get tables names");
while (iterator.hasNext()) {
Table table = iterator.next();
System.out.println(table.getTableName());
}
}
我无法获取我在帐户中创建的 table。你能告诉我我做错了什么吗??
适用于 AWS 的 Java SDK 默认为 us-east-1 区域。您可能没有看到任何表格,因为您在 us-east-1 区域中有 none。如果您的 DynamoDB 表位于不同的区域,您需要指定您希望 SDK 连接的区域。然后您的应用程序将能够在其他区域看到这些表。
我在名为 'test' 的 AWS 账户中的 dynamoDb 中创建了一个 table。我正在尝试通过输入我的凭据并使用 Java 代码来列出我帐户中的所有 tables:
static void listAllTables() {
static BasicAWSCredentials awsCreds = new BasicAWSCredentials("AWSAccessKeyId", "AWSSecretKey");
static DynamoDB dynamoDB = new DynamoDB(new AmazonDynamoDBClient(awsCreds));
TableCollection<ListTablesResult> tables = dynamoDB.listTables();
Iterator<Table> iterator = tables.iterator();
System.out.println("get tables names");
while (iterator.hasNext()) {
Table table = iterator.next();
System.out.println(table.getTableName());
}
}
我无法获取我在帐户中创建的 table。你能告诉我我做错了什么吗??
适用于 AWS 的 Java SDK 默认为 us-east-1 区域。您可能没有看到任何表格,因为您在 us-east-1 区域中有 none。如果您的 DynamoDB 表位于不同的区域,您需要指定您希望 SDK 连接的区域。然后您的应用程序将能够在其他区域看到这些表。