I am currently using Java dynamoMapper to create and query the table. When trying to create a table with a global secondary index, I get the following error
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;
}
Class to create table looks like this
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;
}
I have searched the Amazon site for additional annotations and configuration but nothing came up for DynamoMapper. Is there anyway to do this using ORM or will i have to manually create by using a lower level API?
To add a global secondary index to an existing table, use the UpdateTable operation with the GlobalSecondaryIndexUpdates parameter. You must provide the following: An index name. The name must be unique among all the indexes on the table.
DynamoDB supports two types of secondary indexes: Global secondary index — An index with a partition key and a sort key that can be different from those on the base table. A global secondary index is considered "global" because queries on the index can span all of the data in the base table, across all partitions.
You need to set the provisioned throughput on each secondary index table that will be generated as well.
tableRequest.getGlobalSecondaryIndexes().get(0).setProvisionedThroughput(new ProvisionedThroughput(10l, 10l));
Extension to @Jeremy's answer.
If you have more than one GSI, then you may do it like below. Also you don't need to create ProvisionedThroughput object all the time if they are of same values.
final ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput(5L, 5L);
createRequest.setProvisionedThroughput(provisionedThroughput);
createRequest.getGlobalSecondaryIndexes().forEach(v -> v.setProvisionedThroughput(provisionedThroughput));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With