Java Code Examples for com.amazonaws.services.dynamodbv2.model.CreateTableRequest#setProvisionedThroughput()
The following examples show how to use
com.amazonaws.services.dynamodbv2.model.CreateTableRequest#setProvisionedThroughput() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProductInfoRepositoryIntegrationTest.java From tutorials with MIT License | 7 votes |
@Before public void setup() { try { repository = new ProductInfoRepository(); repository.setMapper(dynamoDBMapper); CreateTableRequest tableRequest = dynamoDBMapper.generateCreateTableRequest(ProductInfo.class); tableRequest.setProvisionedThroughput(new ProvisionedThroughput(1L, 1L)); amazonDynamoDB.createTable(tableRequest); } catch (ResourceInUseException e) { // Do nothing, table already created } // TODO How to handle different environments. i.e. AVOID deleting all entries in ProductInfo on table dynamoDBMapper.batchDelete((List<ProductInfo>) repository.findAll()); }
Example 2
Source File: ScanITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUpTestData() throws Exception { String keyName = "id"; CreateTableRequest createTableRequest = new CreateTableRequest() .withTableName(TABLE_NAME) .withKeySchema(new KeySchemaElement().withAttributeName(keyName).withKeyType(KeyType.HASH)) .withAttributeDefinitions( new AttributeDefinition().withAttributeName(keyName).withAttributeType( ScalarAttributeType.S)); createTableRequest.setProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(10L) .withWriteCapacityUnits(5L)); TableUtils.createTableIfNotExists(dynamo, createTableRequest); TableUtils.waitUntilActive(dynamo, TABLE_NAME); createTestData(); }
Example 3
Source File: DynamoDBCryptoIntegrationTestBase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { // Create a table DynamoDBTestBase.setUpTestBase(); String keyName = KEY_NAME; CreateTableRequest createTableRequest = new CreateTableRequest() .withTableName(TABLE_NAME) .withKeySchema(new KeySchemaElement().withAttributeName(keyName).withKeyType(KeyType.HASH)) .withAttributeDefinitions( new AttributeDefinition().withAttributeName(keyName).withAttributeType( ScalarAttributeType.S)); createTableRequest.setProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(10L) .withWriteCapacityUnits(5L)); if (TableUtils.createTableIfNotExists(dynamo, createTableRequest)) { TableUtils.waitUntilActive(dynamo, TABLE_NAME); } }
Example 4
Source File: DynamoDBCryptoIntegrationTestBase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
protected static void setUpTableWithRangeAttribute() throws Exception { setUp(); String keyName = DynamoDBCryptoIntegrationTestBase.KEY_NAME; String rangeKeyAttributeName = "rangeKey"; CreateTableRequest createTableRequest = new CreateTableRequest() .withTableName(TABLE_WITH_RANGE_ATTRIBUTE) .withKeySchema(new KeySchemaElement().withAttributeName(keyName).withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName(rangeKeyAttributeName).withKeyType(KeyType.RANGE)) .withAttributeDefinitions( new AttributeDefinition().withAttributeName(keyName).withAttributeType( ScalarAttributeType.N), new AttributeDefinition().withAttributeName(rangeKeyAttributeName).withAttributeType( ScalarAttributeType.N)); createTableRequest.setProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(10L) .withWriteCapacityUnits(5L)); if (TableUtils.createTableIfNotExists(dynamo, createTableRequest)) { TableUtils.waitUntilActive(dynamo, TABLE_WITH_RANGE_ATTRIBUTE); } }
Example 5
Source File: MapperSaveConfigCryptoIntegrationTestBase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { DynamoDBCryptoIntegrationTestBase.setUp(); dynamoMapper = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo); CreateTableRequest createTableRequest = new CreateTableRequest() .withTableName(tableName) .withKeySchema(new KeySchemaElement().withAttributeName(hashKeyName).withKeyType(KeyType.HASH)) .withKeySchema(new KeySchemaElement().withAttributeName(rangeKeyName).withKeyType(KeyType.RANGE)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName(hashKeyName) .withAttributeType(ScalarAttributeType.S)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName(rangeKeyName) .withAttributeType(ScalarAttributeType.N)); createTableRequest.setProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT); if (TableUtils.createTableIfNotExists(dynamo, createTableRequest)) { TableUtils.waitUntilActive(dynamo, tableName); } }
Example 6
Source File: AutoGeneratedKeysITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { DynamoDBMapperCryptoIntegrationTestBase.setUp(); // Create a table String keyName = DynamoDBMapperCryptoIntegrationTestBase.KEY_NAME; String rangeKeyAttributeName = "rangeKey"; CreateTableRequest createTableRequest = new CreateTableRequest() .withTableName(TABLE_NAME) .withKeySchema(new KeySchemaElement().withAttributeName(keyName).withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName(rangeKeyAttributeName).withKeyType(KeyType.RANGE)) .withAttributeDefinitions( new AttributeDefinition().withAttributeName(keyName).withAttributeType( ScalarAttributeType.S), new AttributeDefinition().withAttributeName(rangeKeyAttributeName).withAttributeType( ScalarAttributeType.S)); createTableRequest.setProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(10L) .withWriteCapacityUnits(5L)); if (TableUtils.createTableIfNotExists(dynamo, createTableRequest)) { TableUtils.waitUntilActive(dynamo, TABLE_NAME); } }
Example 7
Source File: MarsDynamoDBManagerTest.java From aws-dynamodb-mars-json-demo with Apache License 2.0 | 6 votes |
@Test public void testCreateResourceTable() { final AmazonDynamoDB dynamoDB = PowerMock.createMock(AmazonDynamoDB.class); PowerMock.mockStatic(DynamoDBManager.class); final CreateTableRequest request = new CreateTableRequest(); request.setAttributeDefinitions(MarsDynamoDBManager.RESOURCE_TABLE_ATTRIBUTE_DEFINITIONS); request.setKeySchema(MarsDynamoDBManager.RESOURCE_TABLE_KEY_SCHEMA); request.setProvisionedThroughput(PROVISIONED_THROUGHPUT); request.setTableName(TABLE_NAME); DynamoDBManager.createTable(dynamoDB, request); PowerMock.expectLastCall().andReturn(null); PowerMock.replayAll(); MarsDynamoDBManager.createResourceTable(dynamoDB, TABLE_NAME, PROVISIONED_THROUGHPUT); PowerMock.verifyAll(); }
Example 8
Source File: ProductInfoRepositoryIntegrationTest.java From tutorials with MIT License | 6 votes |
@Before public void setup() throws Exception { try { dynamoDBMapper = new DynamoDBMapper(amazonDynamoDB); CreateTableRequest tableRequest = dynamoDBMapper.generateCreateTableRequest(ProductInfo.class); tableRequest.setProvisionedThroughput(new ProvisionedThroughput(1L, 1L)); amazonDynamoDB.createTable(tableRequest); } catch (ResourceInUseException e) { // Do nothing, table already created } // TODO How to handle different environments. i.e. AVOID deleting all entries in ProductInfo on table dynamoDBMapper.batchDelete((List<ProductInfo>) repository.findAll()); }
Example 9
Source File: MapperSaveConfigCryptoIntegrationTestBase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
/** * Helper method to create a table in Amazon DynamoDB */ protected static void createTestTable( ProvisionedThroughput provisionedThroughput) { CreateTableRequest createTableRequest = new CreateTableRequest() .withTableName(tableName) .withKeySchema( new KeySchemaElement().withAttributeName( hashKeyName).withKeyType( KeyType.HASH)) .withKeySchema( new KeySchemaElement().withAttributeName( rangeKeyName).withKeyType( KeyType.RANGE)) .withAttributeDefinitions( new AttributeDefinition().withAttributeName( hashKeyName).withAttributeType( ScalarAttributeType.S)) .withAttributeDefinitions( new AttributeDefinition().withAttributeName( rangeKeyName).withAttributeType( ScalarAttributeType.N)); createTableRequest.setProvisionedThroughput(provisionedThroughput); TableDescription createdTableDescription = dynamo.createTable( createTableRequest).getTableDescription(); System.out.println("Created Table: " + createdTableDescription); assertEquals(tableName, createdTableDescription.getTableName()); assertNotNull(createdTableDescription.getTableStatus()); assertEquals(hashKeyName, createdTableDescription .getKeySchema().get(0).getAttributeName()); assertEquals(KeyType.HASH.toString(), createdTableDescription .getKeySchema().get(0).getKeyType()); assertEquals(rangeKeyName, createdTableDescription .getKeySchema().get(1).getAttributeName()); assertEquals(KeyType.RANGE.toString(), createdTableDescription .getKeySchema().get(1).getKeyType()); }
Example 10
Source File: MarsDynamoDBManager.java From aws-dynamodb-mars-json-demo with Apache License 2.0 | 5 votes |
/** * Creates the table that stores images. * * @param dynamoDB * {@link AmazonDynamoDB} used to create the image table * @param tableName * name of the table to create * @param tableProvisionedThroughput * initial provisioned throughput for the table * @param timeGSIProvisionedThroughput * initial provisioned throughput for the time-based global secondary index * @param voteGSIProvisionedThroughput * initial provisioned throughput for the vote-based global secondary index * @see <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html">Global Secondary * Indexes</a> ======= initial provisioned throughput for the time-based global secondary index * @see <a * href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ProvisionedThroughputIntro.html">Provisioned * Throughput in Amazon DynamoDB</a> */ public static void createImageTable(final AmazonDynamoDB dynamoDB, final String tableName, final ProvisionedThroughput tableProvisionedThroughput, final ProvisionedThroughput timeGSIProvisionedThroughput, final ProvisionedThroughput voteGSIProvisionedThroughput) { // Set up time GSI final GlobalSecondaryIndex timeGSI = new GlobalSecondaryIndex(); timeGSI.setIndexName(IMAGE_TABLE_TIME_GSI_NAME); timeGSI.setKeySchema(Arrays.asList(IMAGE_TABLE_TIME_GSI_HASH_KSE, IMAGE_TABLE_TIME_GSI_RANGE_KSE)); timeGSI.setProjection(IMAGE_TABLE_TIME_GSI_PROJECTION); timeGSI.setProvisionedThroughput(timeGSIProvisionedThroughput); // Set up vote GSI final GlobalSecondaryIndex voteGSI = new GlobalSecondaryIndex(); voteGSI.setIndexName(IMAGE_TABLE_VOTE_GSI_NAME); voteGSI.setKeySchema(Arrays.asList(IMAGE_TABLE_VOTE_GSI_HASH_KSE, IMAGE_TABLE_VOTE_GSI_RANGE_KSE)); voteGSI.setProjection(IMAGE_TABLE_VOTE_GSI_PROJECTION); voteGSI.setProvisionedThroughput(voteGSIProvisionedThroughput); // Create table final CreateTableRequest request = new CreateTableRequest(); request.setAttributeDefinitions(IMAGE_TABLE_ATTRIBUTE_DEFINITIONS); request.setKeySchema(IMAGE_TABLE_KEY_SCHEMA); request.setGlobalSecondaryIndexes(Arrays.asList(timeGSI, voteGSI)); request.setProvisionedThroughput(tableProvisionedThroughput); request.setTableName(tableName); LOGGER.info("Creating image table: " + request); final TableDescription result = DynamoDBManager.createTable(dynamoDB, request); LOGGER.info("Image table successfully created: " + result); }
Example 11
Source File: MarsDynamoDBManagerTest.java From aws-dynamodb-mars-json-demo with Apache License 2.0 | 5 votes |
@Test public void testCreateImageTable() { final AmazonDynamoDB dynamoDB = PowerMock.createMock(AmazonDynamoDB.class); PowerMock.mockStatic(DynamoDBManager.class); final CreateTableRequest request = new CreateTableRequest(); request.setAttributeDefinitions(MarsDynamoDBManager.IMAGE_TABLE_ATTRIBUTE_DEFINITIONS); request.setKeySchema(MarsDynamoDBManager.IMAGE_TABLE_KEY_SCHEMA); final GlobalSecondaryIndex timeGSI = new GlobalSecondaryIndex(); timeGSI.setIndexName(MarsDynamoDBManager.IMAGE_TABLE_TIME_GSI_NAME); timeGSI.setKeySchema(Arrays.asList(MarsDynamoDBManager.IMAGE_TABLE_TIME_GSI_HASH_KSE, MarsDynamoDBManager.IMAGE_TABLE_TIME_GSI_RANGE_KSE)); timeGSI.setProjection(MarsDynamoDBManager.IMAGE_TABLE_TIME_GSI_PROJECTION); timeGSI.setProvisionedThroughput(PROVISIONED_THROUGHPUT); final GlobalSecondaryIndex voteGSI = new GlobalSecondaryIndex(); voteGSI.setIndexName(MarsDynamoDBManager.IMAGE_TABLE_VOTE_GSI_NAME); voteGSI.setKeySchema(Arrays.asList(MarsDynamoDBManager.IMAGE_TABLE_VOTE_GSI_HASH_KSE, MarsDynamoDBManager.IMAGE_TABLE_VOTE_GSI_RANGE_KSE)); voteGSI.setProjection(MarsDynamoDBManager.IMAGE_TABLE_VOTE_GSI_PROJECTION); voteGSI.setProvisionedThroughput(PROVISIONED_THROUGHPUT); request.setGlobalSecondaryIndexes(Arrays.asList(timeGSI, voteGSI)); request.setProvisionedThroughput(PROVISIONED_THROUGHPUT); request.setTableName(TABLE_NAME); DynamoDBManager.createTable(dynamoDB, request); PowerMock.expectLastCall().andReturn(null); PowerMock.replayAll(); MarsDynamoDBManager.createImageTable(dynamoDB, TABLE_NAME, PROVISIONED_THROUGHPUT, PROVISIONED_THROUGHPUT, PROVISIONED_THROUGHPUT); PowerMock.verifyAll(); }
Example 12
Source File: ApplicationPropertiesConfigurations.java From tutorials with MIT License | 5 votes |
private void initDatabase() { // Create the table DynamoDBMapper mapper = new DynamoDBMapper(amazonDynamoDb); CreateTableRequest tableRequest = mapper.generateCreateTableRequest(ArchaiusProperties.class); tableRequest.setProvisionedThroughput(new ProvisionedThroughput(1L, 1L)); TableUtils.createTableIfNotExists(amazonDynamoDb, tableRequest); // Populate the table ArchaiusProperties property = new ArchaiusProperties("baeldung.archaius.properties.one", "one FROM:dynamoDB"); ArchaiusProperties property3 = new ArchaiusProperties("baeldung.archaius.properties.three", "three FROM:dynamoDB"); repository.saveAll(Arrays.asList(property, property3)); }
Example 13
Source File: DynamoDBUtils.java From amazon-kinesis-connectors with Apache License 2.0 | 5 votes |
/** * 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 * 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); }
Example 14
Source File: DynamoDBCryptoIntegrationTestBase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 4 votes |
protected static void setUpTableWithIndexRangeAttribute(boolean recreateTable) throws Exception { setUp(); if (recreateTable) { dynamo.deleteTable(new DeleteTableRequest().withTableName(TABLE_WITH_INDEX_RANGE_ATTRIBUTE)); waitForTableToBecomeDeleted(TABLE_WITH_INDEX_RANGE_ATTRIBUTE); } String keyName = DynamoDBCryptoIntegrationTestBase.KEY_NAME; String rangeKeyAttributeName = "rangeKey"; String indexFooRangeKeyAttributeName = "indexFooRangeKey"; String indexBarRangeKeyAttributeName = "indexBarRangeKey"; String multipleIndexRangeKeyAttributeName = "multipleIndexRangeKey"; String indexFooName = "index_foo"; String indexBarName = "index_bar"; String indexFooCopyName = "index_foo_copy"; String indexBarCopyName = "index_bar_copy"; CreateTableRequest createTableRequest = new CreateTableRequest() .withTableName(TABLE_WITH_INDEX_RANGE_ATTRIBUTE) .withKeySchema( new KeySchemaElement().withAttributeName(keyName).withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName(rangeKeyAttributeName).withKeyType(KeyType.RANGE)) .withLocalSecondaryIndexes( new LocalSecondaryIndex() .withIndexName(indexFooName) .withKeySchema( new KeySchemaElement().withAttributeName(keyName).withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName(indexFooRangeKeyAttributeName).withKeyType(KeyType.RANGE)) .withProjection(new Projection().withProjectionType(ProjectionType.ALL)), new LocalSecondaryIndex() .withIndexName(indexBarName) .withKeySchema( new KeySchemaElement().withAttributeName(keyName).withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName(indexBarRangeKeyAttributeName).withKeyType(KeyType.RANGE)) .withProjection(new Projection() .withProjectionType(ProjectionType.ALL)), new LocalSecondaryIndex() .withIndexName(indexFooCopyName) .withKeySchema( new KeySchemaElement().withAttributeName(keyName).withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName(multipleIndexRangeKeyAttributeName).withKeyType(KeyType.RANGE)) .withProjection(new Projection() .withProjectionType(ProjectionType.ALL)), new LocalSecondaryIndex() .withIndexName(indexBarCopyName) .withKeySchema( new KeySchemaElement().withAttributeName(keyName).withKeyType(KeyType.HASH), new KeySchemaElement().withAttributeName(multipleIndexRangeKeyAttributeName).withKeyType(KeyType.RANGE)) .withProjection(new Projection() .withProjectionType(ProjectionType.ALL))) .withAttributeDefinitions( new AttributeDefinition().withAttributeName(keyName).withAttributeType(ScalarAttributeType.N), new AttributeDefinition().withAttributeName(rangeKeyAttributeName).withAttributeType(ScalarAttributeType.N), new AttributeDefinition().withAttributeName(indexFooRangeKeyAttributeName).withAttributeType(ScalarAttributeType.N), new AttributeDefinition().withAttributeName(indexBarRangeKeyAttributeName).withAttributeType(ScalarAttributeType.N), new AttributeDefinition().withAttributeName(multipleIndexRangeKeyAttributeName).withAttributeType(ScalarAttributeType.N)); createTableRequest.setProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(10L) .withWriteCapacityUnits(5L)); if (TableUtils.createTableIfNotExists(dynamo, createTableRequest)) { TableUtils.waitUntilActive(dynamo, TABLE_WITH_INDEX_RANGE_ATTRIBUTE); } }
Example 15
Source File: MarsDynamoDBManager.java From aws-dynamodb-mars-json-demo with Apache License 2.0 | 3 votes |
/** * Creates the table that stores resources with an ETag. * * @param dynamoDB * {@link AmazonDynamoDB} used to create DynamoDB table * @param tableName * name of the table to create * @param provisionedThroughput * initial provisioned throughput for the table * @see <a * href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ProvisionedThroughputIntro.html">Provisioned * Througput in Amazon DynamoDB</a> */ public static void createResourceTable(final AmazonDynamoDB dynamoDB, final String tableName, final ProvisionedThroughput provisionedThroughput) { final CreateTableRequest request = new CreateTableRequest(); request.setAttributeDefinitions(RESOURCE_TABLE_ATTRIBUTE_DEFINITIONS); request.setKeySchema(RESOURCE_TABLE_KEY_SCHEMA); request.setProvisionedThroughput(provisionedThroughput); request.setTableName(tableName); LOGGER.info("Creating resource table: " + request); DynamoDBManager.createTable(dynamoDB, request); LOGGER.info("Resource table successfully created"); }