List of usage examples for com.amazonaws.services.dynamodbv2 AmazonDynamoDBClient createTable
@Override
public CreateTableResult createTable(CreateTableRequest request)
The CreateTable
operation adds a new table to your account.
From source file:whgHelper.java
License:Open Source License
public static void setTable(AmazonDynamoDBClient dynamoDB, String tableName) { // Create table if it does not exist yet if (Tables.doesTableExist(dynamoDB, tableName)) { System.out.println("Table " + tableName + " is already ACTIVE"); } else {/* w w w .j av a 2 s. c o m*/ // Create a table with a primary hash key named 'name', which holds a string CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema(new KeySchemaElement().withAttributeName("alertId").withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName("alertId") .withAttributeType(ScalarAttributeType.S)) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L)); TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest) .getTableDescription(); System.out.println("Created Table: " + createdTableDescription); // Wait for it to become active System.out.println("Waiting for " + tableName + " to become ACTIVE..."); Tables.waitForTableToBecomeActive(dynamoDB, tableName); } return; }
From source file:DynamoDBUtils.java
License:Open Source License
/** * Creates the Amazon DynamoDB table if it does not already exist and have the correct schema. Then it * waits for the table to become active. * * @param client//w w w . j ava 2 s. co m * The {@link AmazonDynamoDBClient} with Amazon DynamoDB read and write privileges * @param tableName * The Amazon DynamoDB table to create * @param key * The Amazon DynamoDB table hashkey * @param readCapacityUnits * Number of read capacity units for the Amazon DynamoDB table * @param writeCapacityUnits * Number of write capacity units for the Amazon DynamoDB table * @throws IllegalStateException * Table already exists and schema does not match * @throws IllegalStateException * Table is already getting created */ public static void createTable(AmazonDynamoDBClient client, String tableName, String key, long readCapacityUnits, long writeCapacityUnits) { if (tableExists(client, tableName)) { if (tableHasCorrectSchema(client, tableName, key)) { waitForActive(client, tableName); return; } else { throw new IllegalStateException("Table already exists and schema does not match"); } } CreateTableRequest createTableRequest = new CreateTableRequest(); createTableRequest.setTableName(tableName); createTableRequest.setKeySchema(Arrays.asList(new KeySchemaElement(key, KeyType.HASH))); createTableRequest .setProvisionedThroughput(new ProvisionedThroughput(readCapacityUnits, writeCapacityUnits)); createTableRequest .setAttributeDefinitions(Arrays.asList(new AttributeDefinition(key, ScalarAttributeType.S))); try { client.createTable(createTableRequest); } catch (ResourceInUseException e) { throw new IllegalStateException("The table may already be getting created.", e); } LOG.info("Table " + tableName + " created"); waitForActive(client, tableName); }
From source file:aws.example.dynamodb.CreateTable.java
License:Open Source License
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 HelloTable\n"; if (args.length < 1) { System.out.println(USAGE); System.exit(1);/* w w w.j a v a 2 s . co m*/ } /* Read the name from command args */ String table_name = args[0]; System.out.format("Creating table \"%s\" with a simple primary key: \"Name\".\n", table_name); CreateTableRequest request = new CreateTableRequest() .withAttributeDefinitions(new AttributeDefinition("Name", ScalarAttributeType.S)) .withKeySchema(new KeySchemaElement("Name", KeyType.HASH)) .withProvisionedThroughput(new ProvisionedThroughput(new Long(10), new Long(10))) .withTableName(table_name); final AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(); try { CreateTableResult result = ddb.createTable(request); } catch (AmazonServiceException e) { System.err.println(e.getErrorMessage()); System.exit(1); } System.out.println("Done!"); }
From source file:aws.example.dynamodb.CreateTableCompositeKey.java
License:Open Source License
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);/*from www .j ava 2 s . c o m*/ } /* 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 AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(); try { CreateTableResult result = ddb.createTable(request); } catch (AmazonServiceException e) { System.err.println(e.getErrorMessage()); System.exit(1); } System.out.println("Done!"); }
From source file:awslabs.lab22.SolutionCode.java
License:Open Source License
@Override public void buildTable(AmazonDynamoDBClient ddbClient, String tableName) { System.out.println("Creating table."); CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName); createTableRequest.setAttributeDefinitions(new ArrayList<AttributeDefinition>()); // Define attributes createTableRequest.getAttributeDefinitions() .add(new AttributeDefinition().withAttributeName("Company").withAttributeType("S")); createTableRequest.getAttributeDefinitions() .add(new AttributeDefinition().withAttributeName("Email").withAttributeType("S")); // Define key schema createTableRequest.setKeySchema(new ArrayList<KeySchemaElement>()); createTableRequest.getKeySchema()//w w w . j a va2s . co m .add(new KeySchemaElement().withAttributeName("Company").withKeyType("HASH")); createTableRequest.getKeySchema() .add(new KeySchemaElement().withAttributeName("Email").withKeyType("RANGE")); // Define provisioned throughput createTableRequest.setProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(5L)); // Submit create request ddbClient.createTable(createTableRequest); // Pause until the table is active waitForStatus(ddbClient, tableName, "ACTIVE"); System.out.println("Table created and active."); }
From source file:awslabs.lab51.SolutionCode.java
License:Open Source License
@Override public void buildTable(AmazonDynamoDBClient ddbClient, String tableName) { CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName); createTableRequest.setAttributeDefinitions(new ArrayList<AttributeDefinition>()); // Define attributes createTableRequest.getAttributeDefinitions() .add(new AttributeDefinition().withAttributeName("Key").withAttributeType("S")); createTableRequest.getAttributeDefinitions() .add(new AttributeDefinition().withAttributeName("Bucket").withAttributeType("S")); // Define key schema createTableRequest.setKeySchema(new ArrayList<KeySchemaElement>()); createTableRequest.getKeySchema().add(new KeySchemaElement().withAttributeName("Key").withKeyType("HASH")); createTableRequest.getKeySchema()//from w w w.j a va2 s . c o m .add(new KeySchemaElement().withAttributeName("Bucket").withKeyType("RANGE")); // Define provisioned throughput createTableRequest.setProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(5L).withWriteCapacityUnits(5L)); // Submit create request ddbClient.createTable(createTableRequest); // Pause until the table is active waitForStatus(ddbClient, tableName, "ACTIVE"); labController.logMessageToPage("Table created and active."); }
From source file:com.amazon.services.awsrum.utils.DynamoDBUtils.java
License:Open Source License
public static void createTable(AmazonDynamoDBClient client, String tableName, String key, String rangeKey, long readCapacityUnits, long writeCapacityUnits) { if (tableExists(client, tableName)) { if (tableHasCorrectSchema(client, tableName, key, rangeKey)) { waitForActive(client, tableName); return; } else {//from w w w . ja v a 2s.co m LOG.error("Table already exists and schema does not match"); } } CreateTableRequest createTableRequest = new CreateTableRequest(); createTableRequest.setTableName(tableName); createTableRequest.setKeySchema(Arrays.asList(new KeySchemaElement(key, KeyType.HASH), new KeySchemaElement(rangeKey, KeyType.RANGE))); createTableRequest .setProvisionedThroughput(new ProvisionedThroughput(readCapacityUnits, writeCapacityUnits)); createTableRequest .setAttributeDefinitions(Arrays.asList(new AttributeDefinition(key, ScalarAttributeType.S), new AttributeDefinition(rangeKey, ScalarAttributeType.N))); try { client.createTable(createTableRequest); } catch (ResourceInUseException e) { throw new IllegalStateException("The table may already be getting created.", e); } LOG.info("Table " + tableName + " created"); waitForActive(client, tableName); }
From source file:com.example.kwang27.secmap.DynamoDBManager.java
License:Open Source License
public static void createTable() { Log.d(TAG, "Create table called"); AmazonDynamoDBClient ddb = MainActivity.clientManager.ddb(); KeySchemaElement kse = new KeySchemaElement().withAttributeName("locationNo").withKeyType(KeyType.HASH); AttributeDefinition ad = new AttributeDefinition().withAttributeName("locationNo") .withAttributeType(ScalarAttributeType.N); ProvisionedThroughput pt = new ProvisionedThroughput().withReadCapacityUnits(10l) .withWriteCapacityUnits(5l); CreateTableRequest request = new CreateTableRequest().withTableName(Constants.TEST_TABLE_NAME) .withKeySchema(kse).withAttributeDefinitions(ad).withProvisionedThroughput(pt); try {//from w ww.j a v a2s. c om Log.d(TAG, "Sending Create table request"); ddb.createTable(request); Log.d(TAG, "Create request response successfully recieved"); } catch (AmazonServiceException ex) { Log.e(TAG, "Error sending create table request", ex); MainActivity.clientManager.wipeCredentialsOnAuthError(ex); } }
From source file:com.trk.aboutme.DynamoDB.DynamoDBManagerBooks.java
License:Open Source License
public static void createTable() { Log.d(TAG, "Create Books table called"); AmazonDynamoDBClient ddb = Shelf.clientManager.ddb(); KeySchemaElement kse = new KeySchemaElement().withAttributeName("pageID").withKeyType(KeyType.HASH); AttributeDefinition ad = new AttributeDefinition().withAttributeName("pageID") .withAttributeType(ScalarAttributeType.S); ProvisionedThroughput pt = new ProvisionedThroughput().withReadCapacityUnits(10l) .withWriteCapacityUnits(5l); CreateTableRequest request = new CreateTableRequest().withTableName(Constants.TABLE_NAME_PAGES) .withKeySchema(kse).withAttributeDefinitions(ad).withProvisionedThroughput(pt); try {// w w w . ja v a 2 s . c o m Log.d(TAG, "Sending Create table request"); ddb.createTable(request); Log.d(TAG, "Create request response successfully recieved"); } catch (AmazonServiceException ex) { Log.e(TAG, "Error sending create table request", ex); Shelf.clientManager.wipeCredentialsOnAuthError(ex); } }
From source file:com.trk.aboutme.DynamoDB.DynamoDBManagerUsers.java
License:Open Source License
public static void createTable() { Log.d(TAG, "Create table called"); AmazonDynamoDBClient ddb = Shelf.clientManager.ddb(); KeySchemaElement kse = new KeySchemaElement().withAttributeName("userNo").withKeyType(KeyType.HASH); AttributeDefinition ad = new AttributeDefinition().withAttributeName("userNo") .withAttributeType(ScalarAttributeType.N); ProvisionedThroughput pt = new ProvisionedThroughput().withReadCapacityUnits(10l) .withWriteCapacityUnits(5l); CreateTableRequest request = new CreateTableRequest().withTableName(Constants.TEST_TABLE_NAME) .withKeySchema(kse).withAttributeDefinitions(ad).withProvisionedThroughput(pt); try {// w w w . j a v a 2 s . c o m Log.d(TAG, "Sending Create table request"); ddb.createTable(request); Log.d(TAG, "Create request response successfully recieved"); } catch (AmazonServiceException ex) { Log.e(TAG, "Error sending create table request", ex); Shelf.clientManager.wipeCredentialsOnAuthError(ex); } }