Search in sources :

Example 6 with AttributeDefinition

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

the class CreateTableCompositeKey method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    CreateTable <table>\n\n" + "Where:\n" + "    table - the table to create.\n\n" + "Example:\n" + "    CreateTable GreetingsTable\n";
    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    /* Read the name from command args */
    String table_name = args[0];
    System.out.format("Creating table %s\n with a composite primary key:\n");
    System.out.format("* Language - partition key\n");
    System.out.format("* Greeting - sort key\n");
    CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(new AttributeDefinition("Language", ScalarAttributeType.S), new AttributeDefinition("Greeting", ScalarAttributeType.S)).withKeySchema(new KeySchemaElement("Language", KeyType.HASH), new KeySchemaElement("Greeting", KeyType.RANGE)).withProvisionedThroughput(new ProvisionedThroughput(new Long(10), new Long(10))).withTableName(table_name);
    final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();
    try {
        CreateTableResult result = ddb.createTable(request);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) AttributeDefinition(com.amazonaws.services.dynamodbv2.model.AttributeDefinition) ProvisionedThroughput(com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) CreateTableRequest(com.amazonaws.services.dynamodbv2.model.CreateTableRequest) KeySchemaElement(com.amazonaws.services.dynamodbv2.model.KeySchemaElement) CreateTableResult(com.amazonaws.services.dynamodbv2.model.CreateTableResult)

Aggregations

AttributeDefinition (com.amazonaws.services.dynamodbv2.model.AttributeDefinition)6 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)5 KeySchemaElement (com.amazonaws.services.dynamodbv2.model.KeySchemaElement)5 ProvisionedThroughput (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput)4 AmazonServiceException (com.amazonaws.AmazonServiceException)3 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)3 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)3 CreateTableResult (com.amazonaws.services.dynamodbv2.model.CreateTableResult)2 DeleteTableRequest (com.amazonaws.services.dynamodbv2.model.DeleteTableRequest)2 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)2 ArrayList (java.util.ArrayList)2 AmazonDynamoDBClient (com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)1 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)1 DeleteItemRequest (com.amazonaws.services.dynamodbv2.model.DeleteItemRequest)1 DeleteItemResult (com.amazonaws.services.dynamodbv2.model.DeleteItemResult)1 GetItemRequest (com.amazonaws.services.dynamodbv2.model.GetItemRequest)1 KeyType (com.amazonaws.services.dynamodbv2.model.KeyType)1 ProvisionedThroughputDescription (com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputDescription)1 PutItemRequest (com.amazonaws.services.dynamodbv2.model.PutItemRequest)1 PutItemResult (com.amazonaws.services.dynamodbv2.model.PutItemResult)1