software.amazon.awssdk.services.dynamodb.model.KeySchemaElement Java Examples
The following examples show how to use
software.amazon.awssdk.services.dynamodb.model.KeySchemaElement.
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: DynamoDBUtils.java From quarkus with Apache License 2.0 | 6 votes |
private static CreateTableRequest createTableRequest(String table) { List<AttributeDefinition> attributeDefinitions = new ArrayList<>(); attributeDefinitions .add(AttributeDefinition.builder().attributeName(KEY_NAME).attributeType(ScalarAttributeType.S).build()); attributeDefinitions.add( AttributeDefinition.builder().attributeName(RANGE_NAME).attributeType(ScalarAttributeType.S).build()); List<KeySchemaElement> ks = new ArrayList<>(); ks.add(KeySchemaElement.builder().attributeName(KEY_NAME).keyType(KeyType.HASH).build()); ks.add(KeySchemaElement.builder().attributeName(RANGE_NAME).keyType(KeyType.RANGE).build()); ProvisionedThroughput provisionedthroughput = ProvisionedThroughput.builder().readCapacityUnits(1000L) .writeCapacityUnits(1000L).build(); return CreateTableRequest.builder() .tableName(table) .attributeDefinitions(attributeDefinitions) .keySchema(ks) .provisionedThroughput(provisionedthroughput) .build(); }
Example #2
Source File: SignersIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUpFixture() throws Exception { DynamoDBTestBase.setUpTestBase(); dynamo.createTable(CreateTableRequest.builder().tableName(TABLE_NAME) .keySchema(KeySchemaElement.builder().keyType(KeyType.HASH) .attributeName(HASH_KEY_NAME) .build()) .attributeDefinitions(AttributeDefinition.builder() .attributeType(ScalarAttributeType.S) .attributeName(HASH_KEY_NAME) .build()) .provisionedThroughput(ProvisionedThroughput.builder() .readCapacityUnits(5L) .writeCapacityUnits(5L) .build()) .build()); TableUtils.waitUntilActive(dynamo, TABLE_NAME); putTestData(); }
Example #3
Source File: PaginatorIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUpFixture() throws Exception { DynamoDBTestBase.setUpTestBase(); dynamo.createTable(CreateTableRequest.builder().tableName(TABLE_NAME) .keySchema(KeySchemaElement.builder().keyType(KeyType.HASH) .attributeName(HASH_KEY_NAME) .build()) .attributeDefinitions(AttributeDefinition.builder() .attributeType(ScalarAttributeType.N) .attributeName(HASH_KEY_NAME) .build()) .provisionedThroughput(ProvisionedThroughput.builder() .readCapacityUnits(5L) .writeCapacityUnits(5L) .build()) .build()); TableUtils.waitUntilActive(dynamo, TABLE_NAME); putTestData(); }
Example #4
Source File: MetaStore.java From aws-dynamodb-encryption-java with Apache License 2.0 | 6 votes |
/** * Creates a DynamoDB Table with the correct properties to be used with a ProviderStore. * * @param ddb interface for accessing DynamoDB * @param tableName name of table that stores the meta data of the material. * @param provisionedThroughput required provisioned throughput of the this table. * @return result of create table request. */ public static CreateTableResponse createTable(final DynamoDbClient ddb, final String tableName, final ProvisionedThroughput provisionedThroughput) { return ddb.createTable( CreateTableRequest.builder() .tableName(tableName) .attributeDefinitions(Arrays.asList( AttributeDefinition.builder() .attributeName(DEFAULT_HASH_KEY) .attributeType(ScalarAttributeType.S) .build(), AttributeDefinition.builder() .attributeName(DEFAULT_RANGE_KEY) .attributeType(ScalarAttributeType.N).build())) .keySchema(Arrays.asList( KeySchemaElement.builder() .attributeName(DEFAULT_HASH_KEY) .keyType(KeyType.HASH) .build(), KeySchemaElement.builder() .attributeName(DEFAULT_RANGE_KEY) .keyType(KeyType.RANGE) .build())) .provisionedThroughput(provisionedThroughput).build()); }
Example #5
Source File: DynamoDBUtils.java From ShedLock with Apache License 2.0 | 6 votes |
/** * Creates a locking table with the given name. * <p> * This method does not check if a table with the given name exists already. * * @param ddbClient v2 of DynamoDBClient * @param tableName table to be used * @param throughput AWS {@link ProvisionedThroughput throughput requirements} for the given lock setup * @return the table name * * @throws ResourceInUseException * The operation conflicts with the resource's availability. You attempted to recreate an * existing table. */ public static String createLockTable( DynamoDbClient ddbClient, String tableName, ProvisionedThroughput throughput ) { CreateTableRequest request = CreateTableRequest.builder() .tableName(tableName) .keySchema(KeySchemaElement.builder() .attributeName(ID) .keyType(KeyType.HASH) .build()) .attributeDefinitions(AttributeDefinition.builder() .attributeName(ID) .attributeType(ScalarAttributeType.S) .build()) .provisionedThroughput(throughput) .build(); ddbClient.createTable(request); return tableName; }
Example #6
Source File: CreateTableOperationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void generateRequest_withBinaryKey() { CreateTableOperation<FakeItemWithBinaryKey> operation = CreateTableOperation.create(CreateTableEnhancedRequest.builder() .build()); CreateTableRequest request = operation.generateRequest(FakeItemWithBinaryKey.getTableSchema(), PRIMARY_CONTEXT, null); assertThat(request.tableName(), is(TABLE_NAME)); assertThat(request.keySchema(), containsInAnyOrder(KeySchemaElement.builder() .attributeName("id") .keyType(HASH) .build())); assertThat(request.globalSecondaryIndexes(), is(empty())); assertThat(request.localSecondaryIndexes(), is(empty())); assertThat(request.attributeDefinitions(), containsInAnyOrder( AttributeDefinition.builder() .attributeName("id") .attributeType(ScalarAttributeType.B) .build())); }
Example #7
Source File: DynamoDBIntegrationTestBase.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { setUpCredentials(); dynamo = DynamoDbClient.builder().region(Region.US_EAST_1).credentialsProvider(CREDENTIALS_PROVIDER_CHAIN).build(); // Create a table String keyName = KEY_NAME; CreateTableRequest createTableRequest = CreateTableRequest.builder() .tableName(TABLE_NAME) .keySchema(KeySchemaElement.builder() .attributeName(keyName) .keyType(KeyType.HASH) .build()) .attributeDefinitions( AttributeDefinition.builder().attributeName(keyName) .attributeType(ScalarAttributeType.S) .build()) .provisionedThroughput(ProvisionedThroughput.builder() .readCapacityUnits(10L) .writeCapacityUnits(5L).build()) .build(); if (TableUtils.createTableIfNotExists(dynamo, createTableRequest)) { TableUtils.waitUntilActive(dynamo, TABLE_NAME); } }
Example #8
Source File: CreateTableOperation.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private static Collection<KeySchemaElement> generateKeySchema(String partitionKey, String sortKey) { if (sortKey == null) { return generateKeySchema(partitionKey); } return Collections.unmodifiableList(Arrays.asList(KeySchemaElement.builder() .attributeName(partitionKey) .keyType(KeyType.HASH) .build(), KeySchemaElement.builder() .attributeName(sortKey) .keyType(KeyType.RANGE) .build())); }
Example #9
Source File: DynamoDBLeaseSerializer.java From amazon-kinesis-client with Apache License 2.0 | 5 votes |
@Override public Collection<KeySchemaElement> getKeySchema() { List<KeySchemaElement> keySchema = new ArrayList<>(); keySchema.add(KeySchemaElement.builder().attributeName(LEASE_KEY_KEY).keyType(KeyType.HASH).build()); return keySchema; }
Example #10
Source File: AWSDynamoUtils.java From para with Apache License 2.0 | 5 votes |
/** * Creates a table in AWS DynamoDB which will be shared between apps. * @param readCapacity read capacity * @param writeCapacity write capacity * @return true if created */ public static boolean createSharedTable(long readCapacity, long writeCapacity) { if (StringUtils.isBlank(SHARED_TABLE) || StringUtils.containsWhitespace(SHARED_TABLE) || existsTable(SHARED_TABLE)) { return false; } String table = getTableNameForAppid(SHARED_TABLE); try { GlobalSecondaryIndex secIndex = GlobalSecondaryIndex.builder(). indexName(getSharedIndexName()). provisionedThroughput(b -> b.readCapacityUnits(1L).writeCapacityUnits(1L)). projection(Projection.builder().projectionType(ProjectionType.ALL).build()). keySchema(KeySchemaElement.builder().attributeName(Config._APPID).keyType(KeyType.HASH).build(), KeySchemaElement.builder().attributeName(Config._ID).keyType(KeyType.RANGE).build()).build(); AttributeDefinition[] attributes = new AttributeDefinition[] { AttributeDefinition.builder().attributeName(Config._KEY).attributeType(ScalarAttributeType.S).build(), AttributeDefinition.builder().attributeName(Config._APPID).attributeType(ScalarAttributeType.S).build(), AttributeDefinition.builder().attributeName(Config._ID).attributeType(ScalarAttributeType.S).build() }; CreateTableResponse tbl = getClient().createTable(b -> b.tableName(table). keySchema(KeySchemaElement.builder().attributeName(Config._KEY).keyType(KeyType.HASH).build()). sseSpecification(b2 -> b2.enabled(ENCRYPTION_AT_REST_ENABLED)). attributeDefinitions(attributes). globalSecondaryIndexes(secIndex). provisionedThroughput(b6 -> b6.readCapacityUnits(readCapacity).writeCapacityUnits(writeCapacity))); logger.info("Waiting for DynamoDB table to become ACTIVE..."); waitForActive(table); logger.info("Created shared table '{}', status {}.", table, tbl.tableDescription().tableStatus()); } catch (Exception e) { logger.error(null, e); return false; } return true; }
Example #11
Source File: AWSDynamoUtils.java From para with Apache License 2.0 | 5 votes |
/** * Creates a table in AWS DynamoDB. * @param appid name of the {@link com.erudika.para.core.App} * @param readCapacity read capacity * @param writeCapacity write capacity * @return true if created */ public static boolean createTable(String appid, long readCapacity, long writeCapacity) { if (StringUtils.isBlank(appid)) { return false; } else if (StringUtils.containsWhitespace(appid)) { logger.warn("DynamoDB table name contains whitespace. The name '{}' is invalid.", appid); return false; } else if (existsTable(appid)) { logger.warn("DynamoDB table '{}' already exists.", appid); return false; } try { String table = getTableNameForAppid(appid); CreateTableResponse tbl = getClient().createTable(b -> b.tableName(table). sseSpecification(b2 -> b2.enabled(ENCRYPTION_AT_REST_ENABLED)). provisionedThroughput(b4 -> b4.readCapacityUnits(readCapacity).writeCapacityUnits(writeCapacity)). keySchema(KeySchemaElement.builder().attributeName(Config._KEY).keyType(KeyType.HASH).build()). attributeDefinitions(AttributeDefinition.builder(). attributeName(Config._KEY).attributeType(ScalarAttributeType.S).build())); logger.info("Waiting for DynamoDB table to become ACTIVE..."); waitForActive(table); // NOT IMPLEMENTED in SDK v2: // String status = tbl.waitForActive().getTableStatus(); logger.info("Created DynamoDB table '{}', status {}.", table, tbl.tableDescription().tableStatus()); } catch (Exception e) { logger.error(null, e); return false; } return true; }
Example #12
Source File: DynamoDBIOTestHelper.java From beam with Apache License 2.0 | 5 votes |
private static CreateTableResponse createDynamoTable(String tableName) { ImmutableList<AttributeDefinition> attributeDefinitions = ImmutableList.of( AttributeDefinition.builder() .attributeName(ATTR_NAME_1) .attributeType(ScalarAttributeType.S) .build(), AttributeDefinition.builder() .attributeName(ATTR_NAME_2) .attributeType(ScalarAttributeType.N) .build()); ImmutableList<KeySchemaElement> ks = ImmutableList.of( KeySchemaElement.builder().attributeName(ATTR_NAME_1).keyType(KeyType.HASH).build(), KeySchemaElement.builder().attributeName(ATTR_NAME_2).keyType(KeyType.RANGE).build()); ProvisionedThroughput provisionedthroughput = ProvisionedThroughput.builder().readCapacityUnits(1000L).writeCapacityUnits(1000L).build(); CreateTableRequest request = CreateTableRequest.builder() .tableName(tableName) .attributeDefinitions(attributeDefinitions) .keySchema(ks) .provisionedThroughput(provisionedthroughput) .build(); return dynamoDBClient.createTable(request); }
Example #13
Source File: CreateTable.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static String createTable(DynamoDbClient ddb, String tableName, String key) { // Create the CreateTableRequest object CreateTableRequest request = CreateTableRequest.builder() .attributeDefinitions(AttributeDefinition.builder() .attributeName(key) .attributeType(ScalarAttributeType.S) .build()) .keySchema(KeySchemaElement.builder() .attributeName(key) .keyType(KeyType.HASH) .build()) .provisionedThroughput(ProvisionedThroughput.builder() .readCapacityUnits(new Long(10)) .writeCapacityUnits(new Long(10)) .build()) .tableName(tableName) .build(); String newTable =""; try { CreateTableResponse response = ddb.createTable(request); newTable = response.tableDescription().tableName(); return newTable; } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } // snippet-end:[dynamodb.java2.create_table.main] return ""; }
Example #14
Source File: CreateTableOperationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void generateRequest_withNumericKey() { CreateTableOperation<FakeItemWithNumericSort> operation = CreateTableOperation.create(CreateTableEnhancedRequest.builder() .build()); CreateTableRequest request = operation.generateRequest(FakeItemWithNumericSort.getTableSchema(), PRIMARY_CONTEXT, null); assertThat(request.tableName(), is(TABLE_NAME)); assertThat(request.keySchema(), containsInAnyOrder(KeySchemaElement.builder() .attributeName("id") .keyType(HASH) .build(), KeySchemaElement.builder() .attributeName("sort") .keyType(RANGE) .build())); assertThat(request.globalSecondaryIndexes(), is(DefaultSdkAutoConstructList.getInstance())); assertThat(request.localSecondaryIndexes(), is(DefaultSdkAutoConstructList.getInstance())); assertThat(request.attributeDefinitions(), containsInAnyOrder( AttributeDefinition.builder() .attributeName("id") .attributeType(ScalarAttributeType.S) .build(), AttributeDefinition.builder() .attributeName("sort") .attributeType(ScalarAttributeType.N) .build())); }
Example #15
Source File: CreateTableOperationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override protected boolean matchesSafely(software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex globalSecondaryIndex) { if (!other.indexName().equals(globalSecondaryIndex.indexName())) { return false; } if ((other.projection() != null && !other.projection().equals(globalSecondaryIndex.projection())) || (other.projection() == null && globalSecondaryIndex.projection() != null)) { return false; } return containsInAnyOrder(other.keySchema().toArray(new KeySchemaElement[]{})) .matches(globalSecondaryIndex.keySchema()); }
Example #16
Source File: Aws2Test.java From java-specialagent with Apache License 2.0 | 5 votes |
private static void createTable(final DynamoDbClient dbClient, final String tableName) { final String partitionKeyName = tableName + "Id"; final CreateTableRequest createTableRequest = CreateTableRequest.builder() .tableName(tableName) .keySchema(KeySchemaElement.builder().attributeName(partitionKeyName).keyType(KeyType.HASH).build()) .attributeDefinitions(AttributeDefinition.builder().attributeName(partitionKeyName).attributeType("S").build()) .provisionedThroughput(ProvisionedThroughput.builder().readCapacityUnits(10L).writeCapacityUnits(5L).build()).build(); dbClient.createTable(createTableRequest); }
Example #17
Source File: DynamoDBIntegrationTestBase.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
protected static void setUpTableWithRangeAttribute() throws Exception { setUp(); String keyName = DynamoDBIntegrationTestBase.KEY_NAME; String rangeKeyAttributeName = "rangeKey"; CreateTableRequest createTableRequest = CreateTableRequest.builder() .tableName(TABLE_WITH_RANGE_ATTRIBUTE) .keySchema( KeySchemaElement.builder() .attributeName(keyName) .keyType(KeyType.HASH) .build(), KeySchemaElement.builder() .attributeName(rangeKeyAttributeName) .keyType(KeyType.RANGE) .build()) .attributeDefinitions( AttributeDefinition.builder() .attributeName(keyName) .attributeType(ScalarAttributeType.N) .build(), AttributeDefinition.builder() .attributeName(rangeKeyAttributeName) .attributeType(ScalarAttributeType.N) .build()) .provisionedThroughput(ProvisionedThroughput.builder() .readCapacityUnits(10L) .writeCapacityUnits(5L).build()) .build(); if (TableUtils.createTableIfNotExists(dynamo, createTableRequest)) { TableUtils.waitUntilActive(dynamo, TABLE_WITH_RANGE_ATTRIBUTE); } }
Example #18
Source File: TempTableWithBinaryKey.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override protected CreateTableRequest getCreateTableRequest() { CreateTableRequest request = CreateTableRequest.builder() .tableName(TEMP_BINARY_TABLE_NAME) .keySchema( KeySchemaElement.builder().attributeName(HASH_KEY_NAME) .keyType(KeyType.HASH).build()) .attributeDefinitions( AttributeDefinition.builder().attributeName( HASH_KEY_NAME).attributeType( ScalarAttributeType.B).build()) .provisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) .build(); return request; }
Example #19
Source File: TestTableForParallelScan.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override protected CreateTableRequest getCreateTableRequest() { CreateTableRequest createTableRequest = CreateTableRequest.builder() .tableName(TABLE_NAME) .keySchema( KeySchemaElement.builder().attributeName(HASH_KEY_NAME) .keyType(KeyType.HASH).build()) .attributeDefinitions( AttributeDefinition.builder().attributeName( HASH_KEY_NAME).attributeType( ScalarAttributeType.N).build()) .provisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) .build(); return createTableRequest; }
Example #20
Source File: BasicTempTableWithLowThroughput.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override protected CreateTableRequest getCreateTableRequest() { CreateTableRequest request = CreateTableRequest.builder() .tableName(TEMP_TABLE_NAME) .keySchema( KeySchemaElement.builder().attributeName(HASH_KEY_NAME) .keyType(KeyType.HASH).build()) .attributeDefinitions( AttributeDefinition.builder().attributeName( HASH_KEY_NAME).attributeType( ScalarAttributeType.S).build()) .provisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) .build(); return request; }
Example #21
Source File: BasicTempTable.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override protected CreateTableRequest getCreateTableRequest() { CreateTableRequest request = CreateTableRequest.builder() .tableName(TEMP_TABLE_NAME) .keySchema( KeySchemaElement.builder().attributeName(HASH_KEY_NAME) .keyType(KeyType.HASH).build()) .attributeDefinitions( AttributeDefinition.builder().attributeName( HASH_KEY_NAME).attributeType( ScalarAttributeType.S).build()) .provisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT).build(); return request; }
Example #22
Source File: Aws2ITest.java From java-specialagent with Apache License 2.0 | 5 votes |
private static void createTable(final DynamoDbClient dbClient, final String tableName) { final String partitionKeyName = tableName + "-pk"; final CreateTableRequest createTableRequest = CreateTableRequest .builder().tableName(tableName) .keySchema(KeySchemaElement.builder().attributeName(partitionKeyName).keyType(KeyType.HASH).build()) .attributeDefinitions(AttributeDefinition.builder().attributeName(partitionKeyName).attributeType("S").build()) .provisionedThroughput(ProvisionedThroughput.builder().readCapacityUnits(10L).writeCapacityUnits(5L).build()) .build(); dbClient.createTable(createTableRequest); System.out.println("Table " + tableName + " created"); }
Example #23
Source File: Aws2Test.java From java-specialagent with Apache License 2.0 | 5 votes |
private static CompletableFuture<CreateTableResponse> createTableAsync(final DynamoDbAsyncClient dbClient, final String tableName) { final String partitionKeyName = tableName + "Id"; final CreateTableRequest createTableRequest = CreateTableRequest.builder() .tableName(tableName).keySchema(KeySchemaElement.builder().attributeName(partitionKeyName).keyType(KeyType.HASH).build()) .attributeDefinitions(AttributeDefinition.builder().attributeName(partitionKeyName).attributeType("S").build()) .provisionedThroughput(ProvisionedThroughput.builder().readCapacityUnits(10L).writeCapacityUnits(5L).build()).build(); return dbClient.createTable(createTableRequest); }
Example #24
Source File: CreateTableOperation.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
private static Collection<KeySchemaElement> generateKeySchema(String partitionKey) { return Collections.singletonList(KeySchemaElement.builder() .attributeName(partitionKey) .keyType(KeyType.HASH) .build()); }
Example #25
Source File: CreateTableCompositeKey.java From aws-doc-sdk-examples with Apache License 2.0 | 4 votes |
public static String createTableComKey(DynamoDbClient ddb, String tableName) { CreateTableRequest request = CreateTableRequest.builder() .attributeDefinitions( AttributeDefinition.builder() .attributeName("Language") .attributeType(ScalarAttributeType.S) .build(), AttributeDefinition.builder() .attributeName("Greeting") .attributeType(ScalarAttributeType.S) .build()) .keySchema( KeySchemaElement.builder() .attributeName("Language") .keyType(KeyType.HASH) .build(), KeySchemaElement.builder() .attributeName("Greeting") .keyType(KeyType.RANGE) .build()) .provisionedThroughput( ProvisionedThroughput.builder() .readCapacityUnits(new Long(10)) .writeCapacityUnits(new Long(10)).build()) .tableName(tableName) .build(); String tableId = ""; try { CreateTableResponse result = ddb.createTable(request); tableId = result.tableDescription().tableId(); return tableId; } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } // snippet-end:[dynamodb.java2.create_table_composite_key.main] return ""; }
Example #26
Source File: TempTableWithSecondaryIndexes.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
/** * Table schema: * Hash Key : HASH_KEY_NAME (S) * Range Key : RANGE_KEY_NAME (N) * LSI schema: * Hash Key : HASH_KEY_NAME (S) * Range Key : LSI_RANGE_KEY_NAME (N) * GSI schema: * Hash Key : GSI_HASH_KEY_NAME (N) * Range Key : GSI_RANGE_KEY_NAME (N) */ @Override protected CreateTableRequest getCreateTableRequest() { CreateTableRequest createTableRequest = CreateTableRequest.builder() .tableName(TEMP_TABLE_NAME) .keySchema( KeySchemaElement.builder() .attributeName(HASH_KEY_NAME) .keyType(KeyType.HASH) .build(), KeySchemaElement.builder() .attributeName(RANGE_KEY_NAME) .keyType(KeyType.RANGE) .build()) .attributeDefinitions( AttributeDefinition.builder().attributeName( HASH_KEY_NAME).attributeType( ScalarAttributeType.S).build(), AttributeDefinition.builder().attributeName( RANGE_KEY_NAME).attributeType( ScalarAttributeType.N).build(), AttributeDefinition.builder().attributeName( LSI_RANGE_KEY_NAME).attributeType( ScalarAttributeType.N).build(), AttributeDefinition.builder().attributeName( GSI_HASH_KEY_NAME).attributeType( ScalarAttributeType.S).build(), AttributeDefinition.builder().attributeName( GSI_RANGE_KEY_NAME).attributeType( ScalarAttributeType.N).build()) .provisionedThroughput(BasicTempTable.DEFAULT_PROVISIONED_THROUGHPUT) .localSecondaryIndexes( LocalSecondaryIndex.builder() .indexName(LSI_NAME) .keySchema( KeySchemaElement.builder() .attributeName( HASH_KEY_NAME) .keyType(KeyType.HASH).build(), KeySchemaElement.builder() .attributeName( LSI_RANGE_KEY_NAME) .keyType(KeyType.RANGE).build()) .projection( Projection.builder() .projectionType(ProjectionType.KEYS_ONLY).build()).build()) .globalSecondaryIndexes( GlobalSecondaryIndex.builder().indexName(GSI_NAME) .keySchema( KeySchemaElement.builder() .attributeName( GSI_HASH_KEY_NAME) .keyType(KeyType.HASH).build(), KeySchemaElement.builder() .attributeName( GSI_RANGE_KEY_NAME) .keyType(KeyType.RANGE).build()) .projection( Projection.builder() .projectionType(ProjectionType.KEYS_ONLY).build()) .provisionedThroughput( GSI_PROVISIONED_THROUGHPUT).build()) .build(); return createTableRequest; }
Example #27
Source File: DynamoDBConfiguration.java From liiklus with MIT License | 4 votes |
@Override public void initialize(GenericApplicationContext applicationContext) { var environment = applicationContext.getEnvironment(); if (!"DYNAMODB".equals(environment.getRequiredProperty("storage.positions.type"))) { return; } var dynamoDBProperties = PropertiesUtil.bind(environment, new DynamoDBProperties()); applicationContext.registerBean(DynamoDBPositionsStorage.class, () -> { var builder = DynamoDbAsyncClient.builder(); dynamoDBProperties.getEndpoint() .map(URI::create) .ifPresent(builder::endpointOverride); var dynamoDB = builder .build(); if (dynamoDBProperties.isAutoCreateTable()) { log.info("Going to automatically create a table with name '{}'", dynamoDBProperties.getPositionsTable()); var request = CreateTableRequest.builder() .keySchema( KeySchemaElement.builder().attributeName(DynamoDBPositionsStorage.HASH_KEY_FIELD).keyType(KeyType.HASH).build(), KeySchemaElement.builder().attributeName(DynamoDBPositionsStorage.RANGE_KEY_FIELD).keyType(KeyType.RANGE).build() ) .attributeDefinitions( AttributeDefinition.builder().attributeName(DynamoDBPositionsStorage.HASH_KEY_FIELD).attributeType(ScalarAttributeType.S).build(), AttributeDefinition.builder().attributeName(DynamoDBPositionsStorage.RANGE_KEY_FIELD).attributeType(ScalarAttributeType.S).build() ) .tableName(dynamoDBProperties.getPositionsTable()) .provisionedThroughput(ProvisionedThroughput.builder().readCapacityUnits(10L).writeCapacityUnits(10L).build()) .build(); try { dynamoDB.createTable(request).get(); } catch (Exception e) { throw new IllegalStateException("Can't create positions dynamodb table", e); } } return new DynamoDBPositionsStorage( dynamoDB, dynamoDBProperties.getPositionsTable() ); }); }
Example #28
Source File: LeaseSerializer.java From amazon-kinesis-client with Apache License 2.0 | 2 votes |
/** * @return the key schema for creating a DynamoDB table to store leases */ Collection<KeySchemaElement> getKeySchema();