Java Code Examples for com.amazonaws.services.dynamodbv2.util.TableUtils#createTableIfNotExists()
The following examples show how to use
com.amazonaws.services.dynamodbv2.util.TableUtils#createTableIfNotExists() .
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: DynamoDBServiceImpl2.java From Serverless-Programming-Cookbook with MIT License | 6 votes |
@Override public final Response createTable(final Request request) { final CreateTableRequest createTableRequest = new CreateTableRequest( Arrays.asList( new AttributeDefinition(request.getPartitionKey(), ScalarAttributeType.S), new AttributeDefinition(request.getSortKey(), ScalarAttributeType.N)), request.getTableName(), Arrays.asList( new KeySchemaElement(request.getPartitionKey(), KeyType.HASH), new KeySchemaElement(request.getSortKey(), KeyType.RANGE)), new ProvisionedThroughput(request.getReadCapacityUnits(), request.getWriteCapacityUnits())); TableUtils.createTableIfNotExists(this.dynamoDBClient, createTableRequest); try { TableUtils.waitUntilActive(this.dynamoDBClient, request.getTableName()); } catch (final AmazonClientException | InterruptedException e) { return new Response(null, "Failed in table active check in API version V2: " + e.getMessage()); } return new Response(request.getTableName() + " created with API version V2.", null); }
Example 2
Source File: Application.java From spring-data-dynamodb-examples with Apache License 2.0 | 6 votes |
@Bean public CommandLineRunner multirepo(ConfigurableApplicationContext ctx, CustomerRepository jpaRepository, DeviceRepository dynamoDBRepository, AmazonDynamoDB amazonDynamoDB, DynamoDBMapper dynamoDBMapper, DynamoDBMapperConfig config) { return (args) -> { demoJPA(jpaRepository); CreateTableRequest ctr = dynamoDBMapper.generateCreateTableRequest(Device.class) .withProvisionedThroughput(new ProvisionedThroughput(1L, 1L)); TableUtils.createTableIfNotExists(amazonDynamoDB, ctr); TableUtils.waitUntilActive(amazonDynamoDB, ctr.getTableName()); demoDynamoDB(dynamoDBRepository); ctx.close(); }; }
Example 3
Source File: Application.java From spring-data-dynamodb-examples with Apache License 2.0 | 6 votes |
@Bean public CommandLineRunner rest(ConfigurableApplicationContext ctx, UserRepository dynamoDBRepository, AmazonDynamoDB amazonDynamoDB, DynamoDBMapper dynamoDBMapper, DynamoDBMapperConfig config) { return (args) -> { CreateTableRequest ctr = dynamoDBMapper.generateCreateTableRequest(User.class) .withProvisionedThroughput(new ProvisionedThroughput(1L, 1L)); TableUtils.createTableIfNotExists(amazonDynamoDB, ctr); TableUtils.waitUntilActive(amazonDynamoDB, ctr.getTableName()); createEntities(dynamoDBRepository); log.info(""); log.info("Run curl -v http://localhost:8080/users and follow the HATEOS links"); log.info(""); log.info("Press <enter> to shutdown"); System.in.read(); ctx.close(); }; }
Example 4
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 5
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 6
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 7
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 8
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 9
Source File: DynamoDBOperations.java From geowave with Apache License 2.0 | 6 votes |
private boolean createTable(final String qName, final Supplier<CreateTableRequest> tableRequest) { synchronized (tableExistsCache) { final Boolean tableExists = tableExistsCache.get(qName); if ((tableExists == null) || !tableExists) { final boolean tableCreated = TableUtils.createTableIfNotExists( client, tableRequest.get().withProvisionedThroughput( new ProvisionedThroughput( Long.valueOf(options.getReadCapacity()), Long.valueOf(options.getWriteCapacity())))); if (tableCreated) { try { TableUtils.waitUntilActive(client, qName); } catch (TableNeverTransitionedToStateException | InterruptedException e) { LOGGER.error("Unable to wait for active table '" + qName + "'", e); } } tableExistsCache.put(qName, true); return true; } } return false; }
Example 10
Source File: Application.java From spring-data-dynamodb-examples with Apache License 2.0 | 5 votes |
@Bean public CommandLineRunner custom(ConfigurableApplicationContext ctx, UserRepository userRepository, AmazonDynamoDB amazonDynamoDB, DynamoDBMapper dynamoDBMapper, DynamoDBMapperConfig config) { return (args) -> { CreateTableRequest ctr = dynamoDBMapper.generateCreateTableRequest(User.class) .withProvisionedThroughput(new ProvisionedThroughput(1L, 1L)); TableUtils.createTableIfNotExists(amazonDynamoDB, ctr); TableUtils.waitUntilActive(amazonDynamoDB, ctr.getTableName()); demoCustomInterface(userRepository); ctx.close(); }; }
Example 11
Source File: UserRepositoryIT.java From spring-data-dynamodb-examples with Apache License 2.0 | 5 votes |
@Before public void init() throws Exception { CreateTableRequest ctr = mapper.generateCreateTableRequest(User.class) .withProvisionedThroughput(new ProvisionedThroughput(1L, 1L)); tableWasCreatedForTest = TableUtils.createTableIfNotExists(amazonDynamoDB, ctr); if (tableWasCreatedForTest) { log.info("Created table {}", ctr.getTableName()); } TableUtils.waitUntilActive(amazonDynamoDB, ctr.getTableName()); log.info("Table {} is active", ctr.getTableName()); }
Example 12
Source File: HashKeyOnlyTableWithGSIITCase.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUp() throws Exception { DynamoDBTestBase.setUpTestBase(); List<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>(); keySchema.add(new KeySchemaElement("id", KeyType.HASH)); CreateTableRequest req = new CreateTableRequest( HASH_KEY_ONLY_TABLE_NAME, keySchema) .withProvisionedThroughput(new ProvisionedThroughput(10L, 10L)) .withAttributeDefinitions( new AttributeDefinition("id", ScalarAttributeType.S), new AttributeDefinition("status", ScalarAttributeType.S), new AttributeDefinition("ts", ScalarAttributeType.S)) .withGlobalSecondaryIndexes( new GlobalSecondaryIndex() .withProvisionedThroughput( new ProvisionedThroughput(10L, 10L)) .withIndexName("statusAndCreation") .withKeySchema( new KeySchemaElement("status", KeyType.HASH), new KeySchemaElement("ts", KeyType.RANGE)) .withProjection( new Projection() .withProjectionType(ProjectionType.ALL))); TableUtils.createTableIfNotExists(dynamo, req); TableUtils.waitUntilActive(dynamo, HASH_KEY_ONLY_TABLE_NAME); }
Example 13
Source File: DynamoDBOperations.java From geowave with Apache License 2.0 | 5 votes |
@Override public MetadataWriter createMetadataWriter(final MetadataType metadataType) { final String tableName = getMetadataTableName(metadataType); synchronized (DynamoDBOperations.tableExistsCache) { final Boolean tableExists = DynamoDBOperations.tableExistsCache.get(tableName); if ((tableExists == null) || !tableExists) { final boolean tableCreated = TableUtils.createTableIfNotExists( client, new CreateTableRequest().withTableName(tableName).withAttributeDefinitions( new AttributeDefinition( METADATA_PRIMARY_ID_KEY, ScalarAttributeType.B)).withKeySchema( new KeySchemaElement( METADATA_PRIMARY_ID_KEY, KeyType.HASH)).withAttributeDefinitions( new AttributeDefinition( METADATA_TIMESTAMP_KEY, ScalarAttributeType.N)).withKeySchema( new KeySchemaElement( METADATA_TIMESTAMP_KEY, KeyType.RANGE)).withProvisionedThroughput( new ProvisionedThroughput( Long.valueOf(5), Long.valueOf(5)))); if (tableCreated) { try { TableUtils.waitUntilActive(client, tableName); } catch (TableNeverTransitionedToStateException | InterruptedException e) { LOGGER.error("Unable to wait for active table '" + tableName + "'", e); } } DynamoDBOperations.tableExistsCache.put(tableName, true); } } return new DynamoDBMetadataWriter(this, tableName); }
Example 14
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 15
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); } }