java - 使用 DynamoMapper 和类 Annotation 创建具有全局二级索引的表

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

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

No provisioned throughput specified for the global secondary index 

My java class representing the table has this attribute for the global secondary index.

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

创建表的类如下所示

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 手动创建?

最佳答案

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

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

关于java - 使用 DynamoMapper 和类 Annotation 创建具有全局二级索引的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36817170/

相关文章:

java - 将 XML 转换为 Java 对象

amazon-web-services - 从 AWS Elastic Beanstalk 下载应用程序

youtube - 适用于Amazon Prime的钴

amazon-web-services - 在已创建的资源上部署 lambda 函数

linux - 无法启动 Jenkins : "java.io.FileNotFoundException:/usr/share/java/jenkins/war/META-INF/MANIFEST.MF (No such file or directory)"

java - 如何对数组进行排序并跟踪 java 中的索引

java - 为 Windows 更改 JButton 的禁用前景(字体)颜色

java - 如何解决依赖版本冲突?

amazon-web-services - 安全组的 AWS Cloudformation 跨堆栈引用 - 错误

amazon-web-services - 我在执行 aws cloudformation 模板时遇到错误,抛出错误 ROLLBACK_COMPLETE