Search in sources :

Example 31 with KeySchemaElement

use of com.amazonaws.services.dynamodbv2.model.KeySchemaElement in project aws-doc-sdk-examples by awsdocs.

the class DocumentAPIParallelScan method createTable.

private static void createTable(String tableName, long readCapacityUnits, long writeCapacityUnits, String partitionKeyName, String partitionKeyType, String sortKeyName, String sortKeyType) {
    try {
        System.out.println("Creating table " + tableName);
        List<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>();
        // Partition
        keySchema.add(new KeySchemaElement().withAttributeName(partitionKeyName).withKeyType(KeyType.HASH));
        // key
        List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
        attributeDefinitions.add(new AttributeDefinition().withAttributeName(partitionKeyName).withAttributeType(partitionKeyType));
        if (sortKeyName != null) {
            // Sort
            keySchema.add(new KeySchemaElement().withAttributeName(sortKeyName).withKeyType(KeyType.RANGE));
            // key
            attributeDefinitions.add(new AttributeDefinition().withAttributeName(sortKeyName).withAttributeType(sortKeyType));
        }
        Table table = dynamoDB.createTable(tableName, keySchema, attributeDefinitions, new ProvisionedThroughput().withReadCapacityUnits(readCapacityUnits).withWriteCapacityUnits(writeCapacityUnits));
        System.out.println("Waiting for " + tableName + " to be created...this may take a while...");
        table.waitForActive();
    } catch (Exception e) {
        System.err.println("Failed to create table " + tableName);
        e.printStackTrace(System.err);
    }
}
Also used : Table(com.amazonaws.services.dynamodbv2.document.Table) ArrayList(java.util.ArrayList) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) AmazonServiceException(com.amazonaws.AmazonServiceException)

Aggregations

KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)30 AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)23 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)22 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)21 ArrayList (java.util.ArrayList)16 Table (com.amazonaws.services.dynamodbv2.document.Table)9 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)8 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)6 CreateTableResult (com.amazonaws.services.dynamodbv2.model.CreateTableResult)5 DescribeTableResult (com.amazonaws.services.dynamodbv2.model.DescribeTableResult)5 Projection (com.amazonaws.services.dynamodbv2.model.Projection)5 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)5 AmazonServiceException (com.amazonaws.AmazonServiceException)4 Test (org.junit.Test)4 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)3 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)3 LocalSecondaryIndex (com.amazonaws.services.dynamodbv2.model.LocalSecondaryIndex)3 StreamSpecification (com.amazonaws.services.dynamodbv2.model.StreamSpecification)3 AmazonClientException (com.amazonaws.AmazonClientException)2 ConsumedCapacity (com.amazonaws.services.dynamodbv2.model.ConsumedCapacity)2