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

The following examples show how to use software.amazon.awssdk.services.dynamodb.model.CreateTableRequest. 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: DynamoDBLeaseRefresherTest.java    From amazon-kinesis-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateLeaseTableBillingMode() throws Exception {
    leaseRefresher = new DynamoDBLeaseRefresher(TABLE_NAME, dynamoDbClient, leaseSerializer, CONSISTENT_READS,
            tableCreatorCallback, LeaseManagementConfig.DEFAULT_REQUEST_TIMEOUT, BillingMode.PAY_PER_REQUEST);

    TimeoutException te = setRuleForDependencyTimeout();

    when(dynamoDbClient.describeTable(any(DescribeTableRequest.class))).thenReturn(mockDescribeTableFuture);
    when(mockDescribeTableFuture.get(anyLong(), any()))
            .thenThrow(ResourceNotFoundException.builder().message("Table doesn't exist").build());

    when(dynamoDbClient.createTable(any(CreateTableRequest.class))).thenReturn(mockCreateTableFuture);
    when(mockCreateTableFuture.get(anyLong(), any())).thenThrow(te);

    verifyCancel(mockCreateTableFuture, () -> leaseRefresher.createLeaseTableIfNotExists(10L, 10L));
}
 
Example #2
Source File: CreateTableOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@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"));
}
 
Example #3
Source File: CreateTableOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@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 #4
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 #5
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 #6
Source File: CreateTableOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@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: 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: 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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
Source File: CreateTableOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void getServiceCall_makesTheRightCallAndReturnsResponse() {
    CreateTableOperation<FakeItem> operation = CreateTableOperation.create(CreateTableEnhancedRequest.builder().build());
    CreateTableRequest createTableRequest = CreateTableRequest.builder().build();
    CreateTableResponse expectedResponse = CreateTableResponse.builder().build();
    when(mockDynamoDbClient.createTable(any(CreateTableRequest.class))).thenReturn(expectedResponse);

    CreateTableResponse actualResponse = operation.serviceCall(mockDynamoDbClient).apply(createTableRequest);

    assertThat(actualResponse, sameInstance(expectedResponse));
    verify(mockDynamoDbClient).createTable(same(createTableRequest));
}
 
Example #15
Source File: CreateTableOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@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 #16
Source File: CreateTableOperationTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void generateRequest_withNoProvisionedThroughput() {
    CreateTableOperation<FakeItem> operation = CreateTableOperation.create(CreateTableEnhancedRequest.builder().build());

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

    assertThat(request.billingMode(), is(BillingMode.PAY_PER_REQUEST));
}
 
Example #17
Source File: DynamoDBLeaseRefresherTest.java    From amazon-kinesis-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateLeaseTableTimesOut() throws Exception {
    TimeoutException te = setRuleForDependencyTimeout();

    when(dynamoDbClient.describeTable(any(DescribeTableRequest.class))).thenReturn(mockDescribeTableFuture);
    when(mockDescribeTableFuture.get(anyLong(), any()))
            .thenThrow(ResourceNotFoundException.builder().message("Table doesn't exist").build());

    when(dynamoDbClient.createTable(any(CreateTableRequest.class))).thenReturn(mockCreateTableFuture);
    when(mockCreateTableFuture.get(anyLong(), any())).thenThrow(te);

    verifyCancel(mockCreateTableFuture, () -> leaseRefresher.createLeaseTableIfNotExists(10L, 10L));
}
 
Example #18
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 #19
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 #20
Source File: TableUtils.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the table and ignores any errors if it already exists.
 * @param dynamo The Dynamo client to use.
 * @param createTableRequest The create table request.
 * @return True if created, false otherwise.
 */
public static boolean createTableIfNotExists(final DynamoDbClient dynamo, final CreateTableRequest createTableRequest) {
    try {
        dynamo.createTable(createTableRequest);
        return true;
    } catch (final ResourceInUseException e) {
        if (log.isTraceEnabled()) {
            log.trace("Table " + createTableRequest.tableName() + " already exists", e);
        }
    }
    return false;
}
 
Example #21
Source File: DynamoDBTableResource.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public ResourceStatus getResourceStatus() {
    CreateTableRequest createRequest = getCreateTableRequest();
    TableDescription table;
    try {
        table = getClient().describeTable(DescribeTableRequest.builder().tableName(
                createRequest.tableName()).build()).table();
    } catch (AwsServiceException exception) {
        if (exception.awsErrorDetails().errorCode().equalsIgnoreCase("ResourceNotFoundException")) {
            return ResourceStatus.NOT_EXIST;
        }
        throw exception;
    }

    if (table.tableStatus() == TableStatus.ACTIVE) {
        // returns AVAILABLE only if table KeySchema + LSIs + GSIs all match.
        if (UnorderedCollectionComparator.equalUnorderedCollections(createRequest.keySchema(), table.keySchema())
            && equalUnorderedGsiLists(createRequest.globalSecondaryIndexes(), table.globalSecondaryIndexes())
            && equalUnorderedLsiLists(createRequest.localSecondaryIndexes(), table.localSecondaryIndexes())) {
            return ResourceStatus.AVAILABLE;
        } else {
            return ResourceStatus.EXIST_INCOMPATIBLE_RESOURCE;
        }
    } else if (table.tableStatus() == TableStatus.CREATING
               || table.tableStatus() == TableStatus.UPDATING
               || table.tableStatus() == TableStatus.DELETING) {
        return ResourceStatus.TRANSIENT;
    } else {
        return ResourceStatus.NOT_EXIST;
    }
}
 
Example #22
Source File: TempTableWithBinaryKey.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@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 #23
Source File: TestTableForParallelScan.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@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 #24
Source File: BasicTempTableWithLowThroughput.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@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 #25
Source File: BasicTempTable.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@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 #26
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 #27
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 #28
Source File: CreateTableOperation.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public Function<CreateTableRequest, CompletableFuture<CreateTableResponse>> asyncServiceCall(
    DynamoDbAsyncClient dynamoDbAsyncClient) {

    return dynamoDbAsyncClient::createTable;
}
 
Example #29
Source File: CreateTableOperation.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public Function<CreateTableRequest, CreateTableResponse> serviceCall(DynamoDbClient dynamoDbClient) {
    return dynamoDbClient::createTable;
}
 
Example #30
Source File: TempTableWithSecondaryIndexes.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}