software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType Java Examples
The following examples show how to use
software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType.
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: 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 #7
Source File: StaticTableMetadataTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void getScalarAttributeValueType() { TableMetadata tableMetadata = StaticTableMetadata.builder() .addIndexPartitionKey(primaryIndexName(), "primary_id", AttributeValueType.S) .addIndexSortKey(primaryIndexName(), "primary_sort", AttributeValueType.N) .addIndexPartitionKey(INDEX_NAME, "dummy", AttributeValueType.B) .addIndexSortKey(INDEX_NAME, "dummy2", AttributeValueType.BOOL) .build(); assertThat(tableMetadata.scalarAttributeType("primary_id"), is(Optional.of(ScalarAttributeType.S))); assertThat(tableMetadata.scalarAttributeType("primary_sort"), is(Optional.of(ScalarAttributeType.N))); assertThat(tableMetadata.scalarAttributeType("dummy"), is(Optional.of(ScalarAttributeType.B))); assertThat(tableMetadata.scalarAttributeType("dummy2"), is(Optional.empty())); }
Example #8
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 #9
Source File: CreateTableOperationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void generateRequest_nonReferencedIndicesDoNotCreateExtraAttributeDefinitions() { CreateTableOperation<FakeItemWithIndices> operation = CreateTableOperation.create(CreateTableEnhancedRequest.builder().build()); CreateTableRequest request = operation.generateRequest(FakeItemWithIndices.getTableSchema(), PRIMARY_CONTEXT, null); AttributeDefinition attributeDefinition1 = AttributeDefinition.builder() .attributeName("id") .attributeType(ScalarAttributeType.S) .build(); AttributeDefinition attributeDefinition2 = AttributeDefinition.builder() .attributeName("sort") .attributeType(ScalarAttributeType.S) .build(); assertThat(request.attributeDefinitions(), containsInAnyOrder(attributeDefinition1, attributeDefinition2)); }
Example #10
Source File: StaticTableMetadata.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override public Optional<ScalarAttributeType> scalarAttributeType(String keyAttribute) { AttributeValueType attributeValueType = this.keyAttributes.get(keyAttribute); if (attributeValueType == null) { throw new IllegalArgumentException("Key attribute '" + keyAttribute + "' not found in table metadata."); } return Optional.ofNullable(attributeValueType.scalarAttributeType()); }
Example #11
Source File: DynamoDBLeaseSerializer.java From amazon-kinesis-client with Apache License 2.0 | 5 votes |
@Override public Collection<AttributeDefinition> getAttributeDefinitions() { List<AttributeDefinition> definitions = new ArrayList<>(); definitions.add(AttributeDefinition.builder().attributeName(LEASE_KEY_KEY) .attributeType(ScalarAttributeType.S).build()); return definitions; }
Example #12
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 #13
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 #14
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 #15
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 #16
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 #17
Source File: DynamodbResource.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
@Override public Map<String, String> start() { DockerClientFactory.instance().client(); try { dynamodb = new LocalStackContainer().withServices(Service.DYNAMODB); dynamodb.start(); client = DynamoDbClient.builder() .endpointOverride(new URI(endpoint())) .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("accesskey", "secretKey"))) .httpClientBuilder(UrlConnectionHttpClient.builder()) .region(Region.US_EAST_1).build(); client.createTable(tableRequest -> tableRequest.tableName(TABLE_NAME) .keySchema(keySchema -> keySchema.attributeName("fruitName").keyType(KeyType.HASH)) .attributeDefinitions(attrDef -> attrDef.attributeName("fruitName").attributeType(ScalarAttributeType.S)) .provisionedThroughput(throughput -> throughput.writeCapacityUnits(1L).readCapacityUnits(1L))); } catch (Exception e) { throw new RuntimeException("Could not start Dynamodb localstack server", e); } Map<String, String> properties = new HashMap<>(); properties.put("quarkus.dynamodb.endpoint-override", endpoint()); properties.put("quarkus.dynamodb.aws.region", "us-east-1"); properties.put("quarkus.dynamodb.aws.credentials.type", "static"); properties.put("quarkus.dynamodb.aws.credentials.static-provider.access-key-id", "accessKey"); properties.put("quarkus.dynamodb.aws.credentials.static-provider.secret-access-key", "secretKey"); return properties; }
Example #18
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 #19
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 #20
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 #21
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 #22
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 #23
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 #24
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 #25
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 #26
Source File: TableMetadata.java From aws-sdk-java-v2 with Apache License 2.0 | 2 votes |
/** * Returns the DynamoDb scalar attribute type associated with a key attribute if one is applicable. * @param keyAttribute The key attribute name to return the scalar attribute type of. * @return Optional {@link ScalarAttributeType} of the attribute, or empty if attribute is a non-scalar type. * @throws IllegalArgumentException if the keyAttribute is not found. */ Optional<ScalarAttributeType> scalarAttributeType(String keyAttribute);