use of software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex 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.GlobalSecondaryIndex in project formkiq-core by formkiq.
the class DynamoDbHelper method createDocumentsTable.
/**
* Create Documents Table.
*/
public void createDocumentsTable() {
final Long capacity = Long.valueOf(10);
KeySchemaElement pk = KeySchemaElement.builder().attributeName("PK").keyType(KeyType.HASH).build();
KeySchemaElement sk = KeySchemaElement.builder().attributeName("SK").keyType(KeyType.RANGE).build();
AttributeDefinition a1 = AttributeDefinition.builder().attributeName("PK").attributeType(ScalarAttributeType.S).build();
AttributeDefinition a2 = AttributeDefinition.builder().attributeName("SK").attributeType(ScalarAttributeType.S).build();
AttributeDefinition a3 = AttributeDefinition.builder().attributeName("GSI1PK").attributeType(ScalarAttributeType.S).build();
AttributeDefinition a4 = AttributeDefinition.builder().attributeName("GSI1SK").attributeType(ScalarAttributeType.S).build();
AttributeDefinition a5 = AttributeDefinition.builder().attributeName("GSI2PK").attributeType(ScalarAttributeType.S).build();
AttributeDefinition a6 = AttributeDefinition.builder().attributeName("GSI2SK").attributeType(ScalarAttributeType.S).build();
GlobalSecondaryIndex si1 = GlobalSecondaryIndex.builder().indexName("GSI1").keySchema(KeySchemaElement.builder().attributeName("GSI1PK").keyType(KeyType.HASH).build(), KeySchemaElement.builder().attributeName("GSI1SK").keyType(KeyType.RANGE).build()).projection(Projection.builder().projectionType(ProjectionType.INCLUDE).nonKeyAttributes("inserteddate", "documentId", "tagKey", "tagValue").build()).provisionedThroughput(ProvisionedThroughput.builder().writeCapacityUnits(capacity).readCapacityUnits(capacity).build()).build();
GlobalSecondaryIndex si2 = GlobalSecondaryIndex.builder().indexName("GSI2").keySchema(KeySchemaElement.builder().attributeName("GSI2PK").keyType(KeyType.HASH).build(), KeySchemaElement.builder().attributeName("GSI2SK").keyType(KeyType.RANGE).build()).projection(Projection.builder().projectionType(ProjectionType.INCLUDE).nonKeyAttributes("inserteddate", "documentId", "tagKey", "tagValue").build()).provisionedThroughput(ProvisionedThroughput.builder().writeCapacityUnits(capacity).readCapacityUnits(capacity).build()).build();
CreateTableRequest table = CreateTableRequest.builder().tableName(this.documentTable).keySchema(pk, sk).attributeDefinitions(a1, a2, a3, a4, a5, a6).globalSecondaryIndexes(si1, si2).provisionedThroughput(ProvisionedThroughput.builder().writeCapacityUnits(capacity).readCapacityUnits(capacity).build()).build();
this.db.createTable(table);
}
Aggregations