public void createTables() { ProvisionedThroughput throughput = new ProvisionedThroughput().withReadCapacityUnits(1000L).withWriteCapacityUnits(1000L); CreateTableRequest createEnvironments = dynamoDBMapper .generateCreateTableRequest(EnvironmentDDBRecord.class) .withProvisionedThroughput(throughput); createEnvironments .getGlobalSecondaryIndexes() .forEach(index -> index.withProvisionedThroughput(throughput)); CreateTableRequest createEnvironmentRevisions = dynamoDBMapper .generateCreateTableRequest(EnvironmentRevisionDDBRecord.class) .withProvisionedThroughput(throughput); amazonDynamoDB.createTable(createEnvironments); amazonDynamoDB.createTable(createEnvironmentRevisions); } }
@PostConstruct public void setup() { try { DescribeTableResult result = dynamoDBClient.describeTable(tableConfig.getTableName()); if (!result.getTable().getKeySchema().equals(PROJECT_KEYSCHEMA) || !ImmutableSet.copyOf(result.getTable().getAttributeDefinitions()).equals(ATTRIBUTES)) { throw new IllegalStateException("Invalid schema for user storage dynamodb table. " + "Please remove existing table or change dynamodb table."); } } catch (ResourceNotFoundException e) { dynamoDBClient.createTable(new CreateTableRequest().withTableName(tableConfig.getTableName()) .withKeySchema(PROJECT_KEYSCHEMA) .withAttributeDefinitions(ATTRIBUTES) .withProvisionedThroughput(new ProvisionedThroughput() .withReadCapacityUnits(3L) .withWriteCapacityUnits(3L))); } }
private void createTable() { dynamoDBClient.createTable(new CreateTableRequest() .withTableName(tableConfig.getTableName()).withKeySchema(PROJECT_KEYSCHEMA) .withAttributeDefinitions(ATTRIBUTES) .withProvisionedThroughput(new ProvisionedThroughput() .withReadCapacityUnits(1L) .withWriteCapacityUnits(1L))); }
private void createTable() { dynamoDBClient.createTable(new CreateTableRequest() .withTableName(tableConfig.getTableName()).withKeySchema(PROJECT_KEYSCHEMA) .withAttributeDefinitions(ATTRIBUTES) .withProvisionedThroughput(new ProvisionedThroughput() .withReadCapacityUnits(1L) .withWriteCapacityUnits(1L))); }
private void createTable() { dynamoDBClient.createTable(new CreateTableRequest() .withTableName(tableConfig.getTableName()).withKeySchema(PROJECT_KEYSCHEMA) .withAttributeDefinitions(ATTRIBUTES) .withStreamSpecification(new StreamSpecification().withStreamEnabled(true).withStreamViewType(StreamViewType.NEW_IMAGE)) .withProvisionedThroughput(new ProvisionedThroughput() .withReadCapacityUnits(1L) .withWriteCapacityUnits(1L))); }
private void autoCreateTableIfNotExists() { if (autoCreateTable) { AttributeDefinition partitionKeyDefinition = new AttributeDefinition() .withAttributeName(partitionKeyName) .withAttributeType(ScalarAttributeType.S); KeySchemaElement partitionKeySchema = new KeySchemaElement() .withAttributeName(partitionKeyName) .withKeyType(KeyType.HASH); ProvisionedThroughput throughput = new ProvisionedThroughput() .withReadCapacityUnits(5L) .withWriteCapacityUnits(5L); try { TableUtils.createTableIfNotExists(dynamoDb, new CreateTableRequest() .withTableName(tableName) .withAttributeDefinitions(partitionKeyDefinition) .withKeySchema(partitionKeySchema) .withProvisionedThroughput(throughput)); } catch (AmazonDynamoDBException e) { throw new PersistenceException("Create table request failed", e); } } }
/** * Sets the provisioned throughput for the specified table * * @param tableName * @param readCapUnits * @param writeCapUnits */ public void setProvisionedThroughput(String tableName, long readCapUnits, long writeCapUnits) { ProvisionedThroughput ptDesc = new ProvisionedThroughput() .withReadCapacityUnits(readCapUnits).withWriteCapacityUnits( writeCapUnits); }
static void updateExampleTable() { Table table = dynamoDB.getTable(tableName); System.out.println("Modifying provisioned throughput for " + tableName); try { table.updateTable(new ProvisionedThroughput() .withReadCapacityUnits(6L).withWriteCapacityUnits(7L)); table.waitForActive(); } catch (Exception e) { System.err.println("UpdateTable request failed for " + tableName); System.err.println(e.getMessage()); } }
public static void verifyOrCreateTransactionTable(AmazonDynamoDB client, String tableName, long readCapacityUnits, long writeCapacityUnits, Long waitTimeSeconds) throws InterruptedException { new TableHelper(client).verifyOrCreateTable( tableName, TRANSACTIONS_TABLE_ATTRIBUTES, TRANSACTIONS_TABLE_KEY_SCHEMA, null/*localIndexes*/, new ProvisionedThroughput() .withReadCapacityUnits(readCapacityUnits) .withWriteCapacityUnits(writeCapacityUnits), waitTimeSeconds); }
public static void verifyOrCreateTransactionImagesTable(AmazonDynamoDB client, String tableName, long readCapacityUnits, long writeCapacityUnits, Long waitTimeSeconds) throws InterruptedException { new TableHelper(client).verifyOrCreateTable( tableName, TRANSACTION_IMAGES_TABLE_ATTRIBUTES, TRANSACTION_IMAGES_TABLE_KEY_SCHEMA, null/*localIndexes*/, new ProvisionedThroughput() .withReadCapacityUnits(readCapacityUnits) .withWriteCapacityUnits(writeCapacityUnits), waitTimeSeconds); }
static void createExampleTable() { try { ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>(); attributeDefinitions.add(new AttributeDefinition() .withAttributeName("Id") .withAttributeType("N")); ArrayList<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>(); keySchema.add(new KeySchemaElement() .withAttributeName("Id") .withKeyType(KeyType.HASH)); CreateTableRequest request = new CreateTableRequest() .withTableName(tableName) .withKeySchema(keySchema) .withAttributeDefinitions(attributeDefinitions) .withProvisionedThroughput(new ProvisionedThroughput() .withReadCapacityUnits(5L) .withWriteCapacityUnits(6L)); System.out.println("Issuing CreateTable request for " + tableName); Table table = dynamoDB.createTable(request); System.out.println("Waiting for " + tableName + " to be created...this may take a while..."); table.waitForActive(); getTableInformation(); } catch (Exception e) { System.err.println("CreateTable request failed for " + tableName); System.err.println(e.getMessage()); } }
private static void createTable() { List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>(); attributeDefinitions.add(new AttributeDefinition().withAttributeName("name").withAttributeType("S")); List<KeySchemaElement> ks = new ArrayList<KeySchemaElement>(); ks.add(new KeySchemaElement().withAttributeName("name").withKeyType(KeyType.HASH)); ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput().withReadCapacityUnits(10L) .withWriteCapacityUnits(10L); CreateTableRequest request = new CreateTableRequest().withTableName(TABLENAME) .withAttributeDefinitions(attributeDefinitions).withKeySchema(ks) .withProvisionedThroughput(provisionedThroughput); try { CreateTableResult createdTableDescription = dynamoDBClient.createTable(request); logger.info("Created Table: " + createdTableDescription); // Wait for it to become active waitForTableToBecomeAvailable(TABLENAME); } catch (ResourceInUseException e) { logger.warn("Table already existed", e); } }
/** * Provision the table with given read and write capacity units. * Call will fail if the table is busy, or the new values match the current * ones. * @param readCapacity read units * @param writeCapacity write units * @throws IOException on a failure */ @Retries.RetryTranslated void provisionTable(Long readCapacity, Long writeCapacity) throws IOException { final ProvisionedThroughput toProvision = new ProvisionedThroughput() .withReadCapacityUnits(readCapacity) .withWriteCapacityUnits(writeCapacity); invoker.retry("ProvisionTable", tableName, true, () -> { final ProvisionedThroughputDescription p = table.updateTable(toProvision).getProvisionedThroughput(); LOG.info("Provision table {} in region {}: readCapacityUnits={}, " + "writeCapacityUnits={}", tableName, region, p.getReadCapacityUnits(), p.getWriteCapacityUnits()); }); }
static void updateExampleTable() { ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput() .withReadCapacityUnits(6L) .withWriteCapacityUnits(7L); UpdateTableRequest updateTableRequest = new UpdateTableRequest() .withTableName(tableName) .withProvisionedThroughput(provisionedThroughput); client.updateTable(updateTableRequest); waitForTableToBecomeAvailable(tableName); }
static void createExampleTable() { // Provide the initial provisioned throughput values as Java long data types ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput() .withReadCapacityUnits(5L) .withWriteCapacityUnits(6L); CreateTableRequest request = new CreateTableRequest() .withTableName(tableName) .withProvisionedThroughput(provisionedThroughput); ArrayList<AttributeDefinition> attributeDefinitions= new ArrayList<AttributeDefinition>(); attributeDefinitions.add(new AttributeDefinition().withAttributeName("Id").withAttributeType("N")); request.setAttributeDefinitions(attributeDefinitions); ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>(); tableKeySchema.add(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH)); request.setKeySchema(tableKeySchema); client.createTable(request); waitForTableToBecomeAvailable(tableName); getTableInformation(); }
/** * @return StreamArn */ public static String createTable(AmazonDynamoDBClient client, String tableName) { java.util.List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>(); attributeDefinitions.add(new AttributeDefinition().withAttributeName("Id").withAttributeType("N")); java.util.List<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>(); keySchema.add(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH)); ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput() .withReadCapacityUnits(2L).withWriteCapacityUnits(2L); StreamSpecification streamSpecification = new StreamSpecification(); streamSpecification.setStreamEnabled(true); streamSpecification.setStreamViewType(StreamViewType.NEW_IMAGE); CreateTableRequest createTableRequest = new CreateTableRequest() .withTableName(tableName) .withAttributeDefinitions(attributeDefinitions) .withKeySchema(keySchema) .withProvisionedThroughput(provisionedThroughput) .withStreamSpecification(streamSpecification); try { System.out.println("Creating table " + tableName); CreateTableResult result = client.createTable(createTableRequest); return result.getTableDescription().getLatestStreamArn(); } catch(ResourceInUseException e) { System.out.println("Table already exists."); return describeTable(client, tableName).getTable().getLatestStreamArn(); } }
@Override public void createStoreIfAbsent(String storeName, boolean bBinaryValues) { String tableName = storeToTableName(storeName); if (!Tables.doesTableExist(m_ddbClient, tableName)) { // Create a table with a primary hash key named '_key', which holds a string m_logger.info("Creating table: {}", tableName); CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema(new KeySchemaElement() .withAttributeName(ROW_KEY_ATTR_NAME) .withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition() .withAttributeName(ROW_KEY_ATTR_NAME) .withAttributeType(ScalarAttributeType.S)) .withProvisionedThroughput(new ProvisionedThroughput() .withReadCapacityUnits(READ_CAPACITY_UNITS) .withWriteCapacityUnits(WRITE_CAPACITY_UNITS)); m_ddbClient.createTable(createTableRequest).getTableDescription(); try { Tables.awaitTableToBecomeActive(m_ddbClient, tableName); } catch (InterruptedException e) { throw new RuntimeException(e); } } }
public static void createSessionTable(AmazonDynamoDBClient dynamo, String tableName, long readCapacityUnits, long writeCapacityUnits) { CreateTableRequest request = new CreateTableRequest().withTableName(tableName); request.withKeySchema(new KeySchemaElement().withAttributeName(DynamoSessionItem.SESSION_ID_ATTRIBUTE_NAME) .withKeyType(KeyType.HASH)); request.withAttributeDefinitions( new AttributeDefinition().withAttributeName(DynamoSessionItem.SESSION_ID_ATTRIBUTE_NAME) .withAttributeType(ScalarAttributeType.S)); request.setProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(readCapacityUnits) .withWriteCapacityUnits(writeCapacityUnits)); dynamo.createTable(request); }
.withAttributeType(ScalarAttributeType.S)) .withProvisionedThroughput(new ProvisionedThroughput() .withReadCapacityUnits(m_readCapacityUnits) .withWriteCapacityUnits(m_writeCapacityUnits)); m_client.createTable(createTableRequest);
private void autoCreateTableIfNotExists() { if (autoCreateTable) { AttributeDefinition partitionKeyDefinition = new AttributeDefinition() .withAttributeName(partitionKeyName) .withAttributeType(ScalarAttributeType.S); KeySchemaElement partitionKeySchema = new KeySchemaElement() .withAttributeName(partitionKeyName) .withKeyType(KeyType.HASH); ProvisionedThroughput throughput = new ProvisionedThroughput() .withReadCapacityUnits(5L) .withWriteCapacityUnits(5L); try { TableUtils.createTableIfNotExists(dynamoDb, new CreateTableRequest() .withTableName(tableName) .withAttributeDefinitions(partitionKeyDefinition) .withKeySchema(partitionKeySchema) .withProvisionedThroughput(throughput)); } catch (AmazonDynamoDBException e) { throw new PersistenceException("Create table request failed", e); } } }