Create table with Global secondary index using DynamoMapper and class Annotation

Create table with Global secondary index using DynamoMapper and class Annotation

我目前正在使用 Java dynamoMapper 来创建和查询 table。尝试使用全局二级索引创建 table 时,出现以下错误

No provisioned throughput specified for the global secondary index 

我的javaclass代表table有这个属性为global secondary index。

@DynamoDBIndexHashKey(globalSecondaryIndexName="sender")
    public String getSender() {
    return sender;
}

Class 创建 table 看起来像这样

public boolean createTable() {
try {
DynamoDBMapper mapper = new DynamoDBMapper(client);
CreateTableRequest tableRequest =     mapper.generateCreateTableRequest(entityClass); // 1
tableRequest.setProvisionedThroughput(new ProvisionedThroughput(1000L, 1500L)); // 2
client.createTable(tableRequest); // 3

    } catch (Error e) {
        e.printStackTrace();
        return false;

    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

我在 Amazon 网站上搜索了额外的注释和配置,但没有找到 DynamoMapper。无论如何都可以使用 ORM 来执行此操作,还是我必须使用较低级别 API 手动创建?

您需要在每个将生成的二级索引 table 上设置预置吞吐量。

tableRequest.getGlobalSecondaryIndexes().get(0).setProvisionedThroughput(new ProvisionedThroughput(10l, 10l));

@Jeremy 回答的扩展。

如果您有不止一个 GSI,那么您可以像下面这样操作。如果它们具有相同的值,您也不需要一直创建 ProvisionedThroughput 对象。

 final ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput(5L, 5L);
 createRequest.setProvisionedThroughput(provisionedThroughput);
 createRequest.getGlobalSecondaryIndexes().forEach(v -> v.setProvisionedThroughput(provisionedThroughput));