dynamoDB table 上的 UpdateTableSpec 不工作
UpdateTableSpec on dynamoDB table is not working
任何人都可以告诉我 UpdateTableSpec 是否只能更新 KeySchema 属性,有什么方法可以 update/modify table 具有非 keyschema 属性?我的场景是:我创建了一个 table,其复合键由主键(#id 属性)和范围键(#Name 属性)组成。现在我想添加第三个属性 Gender,它不是 keyschema 的一部分。可能吗?
我正在使用以下代码更新我的 DynamoDB table,但它没有添加性别属性,尽管它成功更新了预配属性:
static void updateTable() {
System.out.println("Updating the table with new attributes ...");
Table table = dynamoDB.getTable(tableName);
UpdateTableSpec updateTableSpec = new UpdateTableSpec();
List<AttributeDefinition> attributeDefinitionList = updateTableSpec.getAttributeDefinitions();
if (null == attributeDefinitionList) {
attributeDefinitionList = new ArrayList<AttributeDefinition>();
}
attributeDefinitionList.add(new AttributeDefinition()
.withAttributeName("Gender")
.withAttributeType("S"));
updateTableSpec.withAttributeDefinitions(attributeDefinitionList)
.withProvisionedThroughput(new ProvisionedThroughput()
.withReadCapacityUnits(6L)
.withWriteCapacityUnits(7L));;
table.updateTable(updateTableSpec);
try {
table.waitForActive();
System.out.println("Table updated succesfully");
} catch (final Exception ex) {
System.out.println("Exception occurred while updating the table");
}
}
您无法更新 DynamoDB 的密钥架构 table。更新 Table API 只能用于(来自 doc):
- Modify the provisioned throughput settings of the table.
- Enable or disable Streams on the table.
- Remove a global secondary index from the table.
- Create a new global secondary index on the table. Once the index begins backfilling, you can use UpdateTable to perform other operations.
我认为,您最好的选择是迁移到具有所需新密钥架构的新 table。可以看到其他选项.
任何人都可以告诉我 UpdateTableSpec 是否只能更新 KeySchema 属性,有什么方法可以 update/modify table 具有非 keyschema 属性?我的场景是:我创建了一个 table,其复合键由主键(#id 属性)和范围键(#Name 属性)组成。现在我想添加第三个属性 Gender,它不是 keyschema 的一部分。可能吗?
我正在使用以下代码更新我的 DynamoDB table,但它没有添加性别属性,尽管它成功更新了预配属性:
static void updateTable() {
System.out.println("Updating the table with new attributes ...");
Table table = dynamoDB.getTable(tableName);
UpdateTableSpec updateTableSpec = new UpdateTableSpec();
List<AttributeDefinition> attributeDefinitionList = updateTableSpec.getAttributeDefinitions();
if (null == attributeDefinitionList) {
attributeDefinitionList = new ArrayList<AttributeDefinition>();
}
attributeDefinitionList.add(new AttributeDefinition()
.withAttributeName("Gender")
.withAttributeType("S"));
updateTableSpec.withAttributeDefinitions(attributeDefinitionList)
.withProvisionedThroughput(new ProvisionedThroughput()
.withReadCapacityUnits(6L)
.withWriteCapacityUnits(7L));;
table.updateTable(updateTableSpec);
try {
table.waitForActive();
System.out.println("Table updated succesfully");
} catch (final Exception ex) {
System.out.println("Exception occurred while updating the table");
}
}
您无法更新 DynamoDB 的密钥架构 table。更新 Table API 只能用于(来自 doc):
- Modify the provisioned throughput settings of the table.
- Enable or disable Streams on the table.
- Remove a global secondary index from the table.
- Create a new global secondary index on the table. Once the index begins backfilling, you can use UpdateTable to perform other operations.
我认为,您最好的选择是迁移到具有所需新密钥架构的新 table。可以看到其他选项