java - dynamoDB 表上的 UpdateTableSpec 不起作用

标签 java amazon-web-services amazon-dynamodb aws-sdk

谁能告诉我 UpdateTableSpec 是否只能更新 KeySchema 属性,是否有任何方法可以更新/修改具有非 keyschema 属性的表?我的场景是:我创建了一个带有复合键的表,其中包含主键(#id 属性)和范围键(#Name 属性)。现在我想添加第三个属性,性别,它不是 keyschema 的一部分。这可能吗?

我正在使用以下代码更新我的 DynamoDB 表,但它没有添加性别属性,尽管它成功更新了预置属性:

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 表的键架构。更新表 API 只能用于(来自 doc ):

  1. Modify the provisioned throughput settings of the table.
  2. Enable or disable Streams on the table.
  3. Remove a global secondary index from the table.
  4. Create a new global secondary index on the table. Once the index begins backfilling, you can use UpdateTable to perform other operations.

我认为,您最好的选择是迁移到具有所需新 key 架构的新表。您可以看到其他选项here .

关于java - dynamoDB 表上的 UpdateTableSpec 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41662233/

相关文章:

amazon-dynamodb - DynamoDB 二次排序

amazon-dynamodb - DynamoDb 流,仅获取新更新

docker - 本地 DynamoDB : Unable to execute HTTP request — Connection refused

java - Eclipse 项目未添加到构建路径

java - 获取变换对象的 x 和 y 点

amazon-web-services - 使用 boto3 从 Python lambda 调用 S3 同步

python - aws codebuild 是否仍然支持 python2.7 运行时?

node.js - 在带有 npm 的 Lambda 函数中使用 AWS Cognito

java - JUnit5 中缺少 org.junit.jupiter.params

java - 实现相同接口(interface)的类之间的关系