13

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?

2 Answers 2

25

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));
Sign up to request clarification or add additional context in comments.

Comments

5

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));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.