software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughput Java Examples

The following examples show how to use software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughput. 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: MetaStoreTests.java    From aws-dynamodb-encryption-java with Apache License 2.0 6 votes vote down vote up
@BeforeMethod
public void setup() {
    localDynamoDb.start();
    targetLocalDynamoDb.start();
    client = localDynamoDb.createClient();
    targetClient = targetLocalDynamoDb.createClient();

    MetaStore.createTable(client, SOURCE_TABLE_NAME, ProvisionedThroughput.builder()
                                                                          .readCapacityUnits(1L)
                                                                          .writeCapacityUnits(1L)
                                                                          .build());
    //Creating Targeted DynamoDB Object
    MetaStore.createTable(targetClient, DESTINATION_TABLE_NAME, ProvisionedThroughput.builder()
                                                                                     .readCapacityUnits(1L)
                                                                                     .writeCapacityUnits(1L)
                                                                                     .build());
    store = new MetaStore(client, SOURCE_TABLE_NAME, ENCRYPTOR);
    targetStore = new MetaStore(targetClient, DESTINATION_TABLE_NAME, TARGET_ENCRYPTOR);
    ctx = EncryptionContext.builder().build();
}
 
Example #2
Source File: MetaStore.java    From aws-dynamodb-encryption-java with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #3
Source File: DynamoDBUtils.java    From quarkus with Apache License 2.0 6 votes vote down vote up
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 #4
Source File: SignersIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@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 #5
Source File: PaginatorIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@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 #6
Source File: DynamoDBIntegrationTestBase.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@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: DynamoDBUtils.java    From ShedLock with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #8
Source File: CreateTableOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #9
Source File: CreateTableOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void generateRequest_withProvisionedThroughput() {
   ProvisionedThroughput provisionedThroughput = ProvisionedThroughput.builder()
                                                                      .writeCapacityUnits(1L)
                                                                      .readCapacityUnits(2L)
                                                                      .build();

    CreateTableOperation<FakeItem> operation = CreateTableOperation.create(
        CreateTableEnhancedRequest.builder().provisionedThroughput(provisionedThroughput).build());

    CreateTableRequest request = operation.generateRequest(FakeItem.getTableSchema(),
                                                           PRIMARY_CONTEXT,
                                                           null);

    assertThat(request.billingMode(), is(BillingMode.PROVISIONED));
    assertThat(request.provisionedThroughput(), is(provisionedThroughput));
}
 
Example #10
Source File: Aws2Test.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
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 #11
Source File: MostRecentProviderTests.java    From aws-dynamodb-encryption-java with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void setup() {
    localDynamoDb.start();
    client = Mockito.spy(localDynamoDb.createLimitedWrappedClient());
    MetaStore.createTable(client, TABLE_NAME, ProvisionedThroughput.builder()
                                                                   .writeCapacityUnits(1L)
                                                                   .readCapacityUnits(1L)
                                                                   .build());
    store = new MetaStore(client, TABLE_NAME, ENCRYPTOR);
    ctx = EncryptionContext.builder().build();
    reset(client);
}
 
Example #12
Source File: DynamoDBLockProviderIntegrationTest.java    From ShedLock with Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void createLockProvider() {
    dynamodb = createClient();
    String lockTable = DynamoDBUtils.createLockTable(
        dynamodb,
        TABLE_NAME,
        ProvisionedThroughput.builder()
            .readCapacityUnits(1L)
            .writeCapacityUnits(1L)
            .build()
    );
    while (getTableStatus(lockTable) != TableStatus.ACTIVE) ;
}
 
Example #13
Source File: DynamoDBIOTestHelper.java    From beam with Apache License 2.0 5 votes vote down vote up
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 #14
Source File: CreateTable.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
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 #15
Source File: UpdateTable.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void updateDynamoDBTable(DynamoDbClient ddb,
                                       String tableName,
                                       Long readCapacity,
                                       Long writeCapacity) {

    System.out.format(
            "Updating %s with new provisioned throughput values\n",
            tableName);
    System.out.format("Read capacity : %d\n", readCapacity);
    System.out.format("Write capacity : %d\n", writeCapacity);

    ProvisionedThroughput tableThroughput = ProvisionedThroughput.builder()
            .readCapacityUnits(readCapacity)
            .writeCapacityUnits(writeCapacity)
            .build();

    UpdateTableRequest request = UpdateTableRequest.builder()
            .provisionedThroughput(tableThroughput)
            .tableName(tableName)
            .build();

    try {
        ddb.updateTable(request);
    } catch (DynamoDbException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }

    // snippet-end:[dynamodb.java2.update_table.main]
    System.out.println("Done!");
}
 
Example #16
Source File: DynamoDBIntegrationTestBase.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
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 #17
Source File: Aws2ITest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
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 #18
Source File: Aws2Test.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
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 #19
Source File: LocalDynamoDbTestBase.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
protected ProvisionedThroughput getDefaultProvisionedThroughput() {
    return DEFAULT_PROVISIONED_THROUGHPUT;
}
 
Example #20
Source File: CreateTableEnhancedRequestTest.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
private ProvisionedThroughput getDefaultProvisionedThroughput() {
    return ProvisionedThroughput.builder()
                                .writeCapacityUnits(1L)
                                .readCapacityUnits(2L)
                                .build();
}
 
Example #21
Source File: CreateTableCompositeKey.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
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 #22
Source File: CreateTableEnhancedRequest.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the provisioned throughput value set on this request object, or null if it has not been set.
 */
public ProvisionedThroughput provisionedThroughput() {
    return provisionedThroughput;
}
 
Example #23
Source File: EnhancedGlobalSecondaryIndex.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
/**
 * The provisioned throughput setting for this global secondary index.
 */
public ProvisionedThroughput provisionedThroughput() {
    return provisionedThroughput;
}
 
Example #24
Source File: DynamoDBConfiguration.java    From liiklus with MIT License 4 votes vote down vote up
@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()
        );
    });
}