use of software.amazon.awssdk.services.dynamodb.model.Projection in project para by Erudika.
the class AWSDynamoUtils method createSharedTable.
/**
* 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, AWS_REGION);
logger.info("Created shared table '{}', status {}.", table, tbl.tableDescription().tableStatus());
if (BACKUPS_ENABLED) {
logger.info("Enabling backups for shared table '{}'...", table);
getClient().updateContinuousBackups((t) -> t.tableName(table).pointInTimeRecoverySpecification((p) -> p.pointInTimeRecoveryEnabled(true)));
}
} catch (Exception e) {
logger.error(null, e);
return false;
}
return true;
}
use of software.amazon.awssdk.services.dynamodb.model.Projection in project aws-sdk-java-v2 by aws.
the class CreateTableOperationTest method generateRequest_withLsiAndGsi.
@Test
public void generateRequest_withLsiAndGsi() {
Projection projection1 = Projection.builder().projectionType(ProjectionType.ALL).build();
Projection projection2 = Projection.builder().projectionType(ProjectionType.KEYS_ONLY).build();
Projection projection3 = Projection.builder().projectionType(ProjectionType.INCLUDE).nonKeyAttributes("key1", "key2").build();
ProvisionedThroughput provisionedThroughput1 = ProvisionedThroughput.builder().readCapacityUnits(1L).writeCapacityUnits(2L).build();
ProvisionedThroughput provisionedThroughput2 = ProvisionedThroughput.builder().readCapacityUnits(3L).writeCapacityUnits(4L).build();
List<EnhancedGlobalSecondaryIndex> globalSecondaryIndexList = Arrays.asList(EnhancedGlobalSecondaryIndex.builder().indexName("gsi_1").projection(projection1).provisionedThroughput(provisionedThroughput1).build(), EnhancedGlobalSecondaryIndex.builder().indexName("gsi_2").projection(projection2).provisionedThroughput(provisionedThroughput2).build());
CreateTableOperation<FakeItemWithIndices> operation = CreateTableOperation.create(CreateTableEnhancedRequest.builder().globalSecondaryIndices(globalSecondaryIndexList).localSecondaryIndices(Collections.singletonList(EnhancedLocalSecondaryIndex.create("lsi_1", projection3))).build());
CreateTableRequest request = operation.generateRequest(FakeItemWithIndices.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()));
software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex expectedGsi1 = software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex.builder().indexName("gsi_1").keySchema(KeySchemaElement.builder().attributeName("gsi_id").keyType(HASH).build(), KeySchemaElement.builder().attributeName("gsi_sort").keyType(RANGE).build()).projection(projection1).provisionedThroughput(provisionedThroughput1).build();
software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex expectedGsi2 = software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex.builder().indexName("gsi_2").keySchema(KeySchemaElement.builder().attributeName("gsi_id").keyType(HASH).build()).projection(projection2).provisionedThroughput(provisionedThroughput2).build();
assertThat(request.globalSecondaryIndexes(), containsInAnyOrder(matchesGsi(expectedGsi1), matchesGsi(expectedGsi2)));
software.amazon.awssdk.services.dynamodb.model.LocalSecondaryIndex expectedLsi = software.amazon.awssdk.services.dynamodb.model.LocalSecondaryIndex.builder().indexName("lsi_1").keySchema(KeySchemaElement.builder().attributeName("id").keyType(HASH).build(), KeySchemaElement.builder().attributeName("lsi_sort").keyType(RANGE).build()).projection(projection3).build();
assertThat(request.localSecondaryIndexes(), containsInAnyOrder(expectedLsi));
assertThat(request.attributeDefinitions(), containsInAnyOrder(AttributeDefinition.builder().attributeName("id").attributeType(ScalarAttributeType.S).build(), AttributeDefinition.builder().attributeName("sort").attributeType(ScalarAttributeType.S).build(), AttributeDefinition.builder().attributeName("lsi_sort").attributeType(ScalarAttributeType.S).build(), AttributeDefinition.builder().attributeName("gsi_id").attributeType(ScalarAttributeType.S).build(), AttributeDefinition.builder().attributeName("gsi_sort").attributeType(ScalarAttributeType.S).build()));
}
use of software.amazon.awssdk.services.dynamodb.model.Projection in project aws-sdk-java-v2 by aws.
the class CreateTableOperationTest method generateRequest_validLsiAsGsiReference.
@Test
public void generateRequest_validLsiAsGsiReference() {
List<EnhancedGlobalSecondaryIndex> validLsiList = Collections.singletonList(EnhancedGlobalSecondaryIndex.builder().indexName("lsi_1").projection(p -> p.projectionType(ProjectionType.ALL)).provisionedThroughput(p -> p.readCapacityUnits(1L).writeCapacityUnits(1L)).build());
CreateTableOperation<FakeItemWithIndices> operation = CreateTableOperation.create(CreateTableEnhancedRequest.builder().globalSecondaryIndices(validLsiList).build());
CreateTableRequest request = operation.generateRequest(FakeItemWithIndices.getTableSchema(), PRIMARY_CONTEXT, null);
assertThat(request.globalSecondaryIndexes().size(), is(1));
software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex globalSecondaryIndex = request.globalSecondaryIndexes().get(0);
assertThat(globalSecondaryIndex.indexName(), is("lsi_1"));
}
use of software.amazon.awssdk.services.dynamodb.model.Projection in project aws-sdk-java-v2 by aws.
the class CreateTableOperationTest method generateRequest_invalidGsi.
@Test(expected = IllegalArgumentException.class)
public void generateRequest_invalidGsi() {
ProvisionedThroughput provisionedThroughput = ProvisionedThroughput.builder().readCapacityUnits(1L).writeCapacityUnits(1L).build();
List<EnhancedGlobalSecondaryIndex> invalidGsiList = Collections.singletonList(EnhancedGlobalSecondaryIndex.builder().indexName("invalid").projection(p -> p.projectionType(ProjectionType.ALL)).provisionedThroughput(provisionedThroughput).build());
CreateTableOperation<FakeItem> operation = CreateTableOperation.create(CreateTableEnhancedRequest.builder().globalSecondaryIndices(invalidGsiList).build());
operation.generateRequest(FakeItem.getTableSchema(), PRIMARY_CONTEXT, null);
}
use of software.amazon.awssdk.services.dynamodb.model.Projection in project serve by pytorch.
the class DDBSnapshotSerializerTest method createTable.
private void createTable() {
ProvisionedThroughput provThroughput = ProvisionedThroughput.builder().readCapacityUnits(10L).writeCapacityUnits(5L).build();
Projection projectAll = Projection.builder().projectionType(ProjectionType.ALL).build();
EnhancedGlobalSecondaryIndex gsi = EnhancedGlobalSecondaryIndex.builder().indexName("createdOnMonth-index").projection(projectAll).provisionedThroughput(provThroughput).build();
CreateTableEnhancedRequest createTableReq = CreateTableEnhancedRequest.builder().globalSecondaryIndices(Arrays.asList(gsi)).build();
snapshotTable.createTable(createTableReq);
}
Aggregations