在 Java 创建 table 之后创建 DynamoDB 全局二级索引
Create DynamoDB Global Secondary Index after table creation in Java
是否可以从 java 以编程方式在现有 table 上创建 GSI?我知道使用
创建新的 table 是可能的
dynamoDB.createTable(new CreateTableRequest().withGlobalSecondaryIndexes(index));
我也知道可以在从网络创建 table 后创建索引。
您将需要使用 GlobalSecondaryIndexUpdate 方法来执行此操作,如下所述:https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_GlobalSecondaryIndexUpdate.html
它应该看起来像这样
CreateGlobalSecondaryIndexAction action = CreateGlobalSecondaryIndexAction
.builder()
.indexName("index-name")
.keySchema(theSchema)
.build();
GlobalSecondaryIndexUpdate index = GlobalSecondaryIndexUpdate
.builder()
.create(action)
.build();
UpdateTableRequest request = UpdateTableRequest
.builder()
.tableName("table-name")
.globalSecondaryIndexUpdates(index)
.build();
dynamoDbClient.updateTable(request);
是否可以从 java 以编程方式在现有 table 上创建 GSI?我知道使用
创建新的 table 是可能的dynamoDB.createTable(new CreateTableRequest().withGlobalSecondaryIndexes(index));
我也知道可以在从网络创建 table 后创建索引。
您将需要使用 GlobalSecondaryIndexUpdate 方法来执行此操作,如下所述:https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_GlobalSecondaryIndexUpdate.html
它应该看起来像这样
CreateGlobalSecondaryIndexAction action = CreateGlobalSecondaryIndexAction
.builder()
.indexName("index-name")
.keySchema(theSchema)
.build();
GlobalSecondaryIndexUpdate index = GlobalSecondaryIndexUpdate
.builder()
.create(action)
.build();
UpdateTableRequest request = UpdateTableRequest
.builder()
.tableName("table-name")
.globalSecondaryIndexUpdates(index)
.build();
dynamoDbClient.updateTable(request);