com.amazonaws.services.dynamodbv2.model.KeySchemaElement Java Examples

The following examples show how to use com.amazonaws.services.dynamodbv2.model.KeySchemaElement. 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: MoviesCreateTable.java    From aws-dynamodb-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        AmazonDynamoDBClient client = new AmazonDynamoDBClient();
        
        client.setEndpoint("http://localhost:8000");
        DynamoDB dynamoDB = new DynamoDB(client);
        
        String tableName = "Movies";
        Table table = dynamoDB.createTable(tableName,
                Arrays.asList(
                        new KeySchemaElement("year", KeyType.HASH),
                        new KeySchemaElement("title", KeyType.RANGE)), 
                Arrays.asList(
                        new AttributeDefinition("year", ScalarAttributeType.N),
                        new AttributeDefinition("title", ScalarAttributeType.S)), 
                new ProvisionedThroughput(10L, 10L));

        try {
            TableUtils.waitUntilActive(client, tableName);
            System.out.println("Table status: " + table.getDescription().getTableStatus());
        } catch (AmazonClientException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
 
Example #2
Source File: AwsTest.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
private static Future<CreateTableResult> createTableAsync(final AmazonDynamoDBAsync dbClient, final String tableName) {
  final String partitionKeyName = tableName + "Id";
  final CreateTableRequest createTableRequest = new CreateTableRequest()
    .withTableName(tableName).withKeySchema(new KeySchemaElement().withAttributeName(partitionKeyName).withKeyType(KeyType.HASH))
    .withAttributeDefinitions(new AttributeDefinition().withAttributeName(partitionKeyName).withAttributeType("S"))
    .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(5L));

  return dbClient.createTableAsync(createTableRequest, new AsyncHandler<CreateTableRequest,CreateTableResult>() {
    @Override
    public void onError(final Exception exception) {
    }

    @Override
    public void onSuccess(final CreateTableRequest request, final CreateTableResult createTableResult) {
    }
  });
}
 
Example #3
Source File: DynamoDBServiceImpl1.java    From Serverless-Programming-Cookbook with MIT License 6 votes vote down vote up
@Override
public final Response createTable(final Request request) {

    if (tableExist(request.getTableName())) {
        return new Response(null, request.getTableName() + " already exist. Checked with version V1.");
    }

    Table table = dynamoDB.createTable(request.getTableName(),
            Arrays.asList(
                    new KeySchemaElement(request.getPartitionKey(), KeyType.HASH),  //Partition key
                    new KeySchemaElement(request.getSortKey(), KeyType.RANGE)), //Sort key
            Arrays.asList(
                    new AttributeDefinition(request.getPartitionKey(), ScalarAttributeType.S),
                    new AttributeDefinition(request.getSortKey(), ScalarAttributeType.N)),
            new ProvisionedThroughput(request.getReadCapacityUnits(), request.getWriteCapacityUnits()));

    if (request.isWaitForActive()) {
        try {
            table.waitForActive();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    return new Response(request.getTableName() + " created with API version V1.", null);
}
 
Example #4
Source File: DynamoDBServiceImpl2.java    From Serverless-Programming-Cookbook with MIT License 6 votes vote down vote up
@Override
public final Response createTable(final Request request) {

    final CreateTableRequest createTableRequest = new CreateTableRequest(
            Arrays.asList(
                    new AttributeDefinition(request.getPartitionKey(), ScalarAttributeType.S),
                    new AttributeDefinition(request.getSortKey(), ScalarAttributeType.N)),
            request.getTableName(),
            Arrays.asList(
                    new KeySchemaElement(request.getPartitionKey(), KeyType.HASH),
                    new KeySchemaElement(request.getSortKey(), KeyType.RANGE)),
            new ProvisionedThroughput(request.getReadCapacityUnits(), request.getWriteCapacityUnits()));

    TableUtils.createTableIfNotExists(this.dynamoDBClient, createTableRequest);

    try {
        TableUtils.waitUntilActive(this.dynamoDBClient, request.getTableName());
    } catch (final AmazonClientException | InterruptedException e) {
        return new Response(null, "Failed in table active check in API version V2: " + e.getMessage());
    }

    return new Response(request.getTableName() + " created with API version V2.", null);
}
 
Example #5
Source File: GenericDynamoDB.java    From strongbox with Apache License 2.0 6 votes vote down vote up
public CreateTableRequest constructCreateTableRequest() {
    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName(partitionKeyName.toString()).withAttributeType("S"));
    attributeDefinitions.add(new AttributeDefinition().withAttributeName(sortKeyName.toString()).withAttributeType("N"));

    ArrayList<KeySchemaElement> keySchema = new ArrayList<>();
    keySchema.add(new KeySchemaElement().withAttributeName(partitionKeyName.toString()).withKeyType(KeyType.HASH));
    keySchema.add(new KeySchemaElement().withAttributeName(sortKeyName.toString()).withKeyType(KeyType.RANGE));

    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
            .withReadCapacityUnits(1L)
            .withWriteCapacityUnits(1L);
    CreateTableRequest request = new CreateTableRequest()
            .withTableName(tableName)
            .withKeySchema(keySchema)
            .withAttributeDefinitions(attributeDefinitions)
            .withProvisionedThroughput(provisionedThroughput);
    return request;
}
 
Example #6
Source File: HiveDynamoDBInputFormat.java    From emr-dynamodb-connector with Apache License 2.0 6 votes vote down vote up
private DynamoDBQueryFilter getQueryFilter(JobConf conf, Map<String, String>
    hiveDynamoDBMapping, Map<String, String> hiveTypeMapping) throws IOException {
  if (hiveDynamoDBMapping == null) {
    /*
     * Column mapping may be null when user has mapped a DynamoDB item
     * onto a single hive map<string, string> column.
     */
    return new DynamoDBQueryFilter();
  }

  DynamoDBClient client = new DynamoDBClient(conf);
  String filterExprSerialized = conf.get(TableScanDesc.FILTER_EXPR_CONF_STR);
  if (filterExprSerialized == null) {
    return new DynamoDBQueryFilter();
  }
  ExprNodeDesc filterExpr =
      ShimsLoader.getHiveShims().deserializeExpression(filterExprSerialized);

  DynamoDBFilterPushdown pushdown = new DynamoDBFilterPushdown();
  List<KeySchemaElement> schema =
      client.describeTable(conf.get(DynamoDBConstants.TABLE_NAME)).getKeySchema();
  DynamoDBQueryFilter queryFilter = pushdown.predicateToDynamoDBFilter(
      schema, hiveDynamoDBMapping, hiveTypeMapping, filterExpr);
  return queryFilter;
}
 
Example #7
Source File: DynamoDBRecordReaderTest.java    From emr-dynamodb-connector with Apache License 2.0 6 votes vote down vote up
private TableDescription getTableDescription(String hashType, String rangeType) {
  List<KeySchemaElement> keySchema = new ArrayList<>();
  List<AttributeDefinition> definitions = new ArrayList<>();

  keySchema.add(new KeySchemaElement().withAttributeName("hashKey").withKeyType(KeyType.HASH));
  definitions.add(new AttributeDefinition().withAttributeName("hashKey").withAttributeType
      (hashType));

  if (rangeType != null) {
    keySchema.add(new KeySchemaElement().withAttributeName("rangeKey").withKeyType(KeyType
        .RANGE));
    definitions.add(new AttributeDefinition().withAttributeName("rangeKey").withAttributeType
        (rangeType));
  }

  TableDescription description = new TableDescription().withKeySchema(keySchema)
      .withAttributeDefinitions(definitions).withProvisionedThroughput(new
          ProvisionedThroughputDescription().withReadCapacityUnits(1000L)
          .withWriteCapacityUnits(1000L));
  return description;
}
 
Example #8
Source File: LowLevelTableExample.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
static void createExampleTable() {

        // Provide the initial provisioned throughput values as Java long data
        // types
        ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput().withReadCapacityUnits(5L)
            .withWriteCapacityUnits(6L);
        CreateTableRequest request = new CreateTableRequest().withTableName(tableName)
            .withProvisionedThroughput(provisionedThroughput);

        ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
        attributeDefinitions.add(new AttributeDefinition().withAttributeName("Id").withAttributeType("N"));
        request.setAttributeDefinitions(attributeDefinitions);

        ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
        tableKeySchema.add(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH)); // Partition
                                                                                                      // key
        request.setKeySchema(tableKeySchema);

        client.createTable(request);

        waitForTableToBecomeAvailable(tableName);

        getTableInformation();

    }
 
Example #9
Source File: DynamoDBEmbeddedTest.java    From aws-dynamodb-examples with Apache License 2.0 6 votes vote down vote up
private static CreateTableResult createTable(AmazonDynamoDB ddb, String tableName, String hashKeyName) {
    List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition(hashKeyName, ScalarAttributeType.S));

    List<KeySchemaElement> ks = new ArrayList<KeySchemaElement>();
    ks.add(new KeySchemaElement(hashKeyName, KeyType.HASH));

    ProvisionedThroughput provisionedthroughput = new ProvisionedThroughput(1000L, 1000L);

    CreateTableRequest request =
        new CreateTableRequest()
            .withTableName(tableName)
            .withAttributeDefinitions(attributeDefinitions)
            .withKeySchema(ks)
            .withProvisionedThroughput(provisionedthroughput);

    return ddb.createTable(request);
}
 
Example #10
Source File: DynamoDBDynamicFaultInjection.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
private static void createTable() {
    List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName("name").withAttributeType("S"));

    List<KeySchemaElement> ks = new ArrayList<KeySchemaElement>();
    ks.add(new KeySchemaElement().withAttributeName("name").withKeyType(KeyType.HASH)); // Partition
                                                                                        // key

    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput().withReadCapacityUnits(10L)
        .withWriteCapacityUnits(10L);

    CreateTableRequest request = new CreateTableRequest().withTableName(TABLENAME)
        .withAttributeDefinitions(attributeDefinitions).withKeySchema(ks)
        .withProvisionedThroughput(provisionedThroughput);

    try {
        CreateTableResult createdTableDescription = dynamoDBClient.createTable(request);
        logger.info("Created Table: " + createdTableDescription);
        // Wait for it to become active
        waitForTableToBecomeAvailable(TABLENAME);
    }
    catch (ResourceInUseException e) {
        logger.warn("Table already existed", e);
    }
}
 
Example #11
Source File: TableHelper.java    From dynamodb-transactions with Apache License 2.0 6 votes vote down vote up
public void waitForTableActive(String tableName, 
    List<AttributeDefinition> definitions, 
    List<KeySchemaElement> keySchema,
    List<LocalSecondaryIndex> localIndexes,
    long waitTimeSeconds) throws InterruptedException {
    
    if(waitTimeSeconds < 0) {
        throw new IllegalArgumentException("Invalid waitTimeSeconds " + waitTimeSeconds);
    }
    
    long startTimeMs = System.currentTimeMillis();
    long elapsedMs = 0;
    do {
        String status = verifyTableExists(tableName, definitions, keySchema, localIndexes);
        if(TableStatus.ACTIVE.toString().equals(status)) {
            return;
        }
        if(TableStatus.DELETING.toString().equals(status)) {
            throw new ResourceInUseException("Table " + tableName + " is " + status + ", and waiting for it to become ACTIVE is not useful.");
        }
        Thread.sleep(10 * 1000);
        elapsedMs = System.currentTimeMillis() - startTimeMs; 
    } while(elapsedMs / 1000.0 < waitTimeSeconds);
    
    throw new ResourceInUseException("Table " + tableName + " did not become ACTIVE after " + waitTimeSeconds + " seconds.");
}
 
Example #12
Source File: UserAuthentication.java    From amazon-cognito-developer-authentication-sample with Apache License 2.0 6 votes vote down vote up
/**
 * Used to create the Identity Table. This function only needs to be called
 * once.
 */
protected void createIdentityTable() throws DataAccessException {
    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
            .withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L);

    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions
            .add(new AttributeDefinition().withAttributeName(ATTRIBUTE_USERNAME).withAttributeType("S"));

    ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
    tableKeySchema.add(new KeySchemaElement().withAttributeName(ATTRIBUTE_USERNAME).withKeyType(KeyType.HASH));

    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(USER_TABLE)
            .withProvisionedThroughput(provisionedThroughput)
            .withAttributeDefinitions(attributeDefinitions)
            .withKeySchema(tableKeySchema);

    try {
        ddb.createTable(createTableRequest);
    } catch (AmazonClientException e) {
        throw new DataAccessException("Failed to create table: " + USER_TABLE, e);
    }
}
 
Example #13
Source File: DeviceAuthentication.java    From amazon-cognito-developer-authentication-sample with Apache License 2.0 6 votes vote down vote up
/**
 * Used to create the device table. This function only needs to be called
 * once.
 */
protected void createDeviceTable() throws DataAccessException {
    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
            .withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L);

    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName(
            ATTRIBUTE_UID).withAttributeType("S"));

    ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
    tableKeySchema.add(new KeySchemaElement().withAttributeName(ATTRIBUTE_UID)
            .withKeyType(KeyType.HASH));

    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(DEVICE_TABLE)
            .withProvisionedThroughput(provisionedThroughput)
            .withAttributeDefinitions(attributeDefinitions)
            .withKeySchema(tableKeySchema);

    try {
        ddb.createTable(createTableRequest);
    } catch (AmazonClientException e) {
        throw new DataAccessException("Failed to create table: " + DEVICE_TABLE, e);
    }
}
 
Example #14
Source File: DynamoDBCryptoIntegrationTestBase.java    From aws-dynamodb-encryption-java with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    // Create a table
    DynamoDBTestBase.setUpTestBase();
    String keyName = KEY_NAME;
    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(TABLE_NAME)
            .withKeySchema(new KeySchemaElement().withAttributeName(keyName).withKeyType(KeyType.HASH))
            .withAttributeDefinitions(
                    new AttributeDefinition().withAttributeName(keyName).withAttributeType(
                            ScalarAttributeType.S));
    createTableRequest.setProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L));

    if (TableUtils.createTableIfNotExists(dynamo, createTableRequest)) {
        TableUtils.waitUntilActive(dynamo, TABLE_NAME);
    }
}
 
Example #15
Source File: DynamoDSETranslatorJSONBlob.java    From dynamo-cassandra-proxy with Apache License 2.0 6 votes vote down vote up
public String getPrimaryKey(List<KeySchemaElement> keySchema){
    String partitionKey = null;
    String clusteringColumn = null;

    for (KeySchemaElement keySchemaElement : keySchema) {
        String type = keySchemaElement.getKeyType();
        String name = keySchemaElement.getAttributeName();
        if (type.equals(HASH.toString()))
            partitionKey = name;

        else if (type.equals(RANGE.toString()))
            clusteringColumn = name;
    }
    String primaryKey;
    if(clusteringColumn != null)
        primaryKey = String.format("((\"%s\"), \"%s\")", partitionKey, clusteringColumn);
    else
        primaryKey = String.format("(\"%s\")", partitionKey);

    return primaryKey;
}
 
Example #16
Source File: LowLevelTableExample.java    From aws-dynamodb-examples with Apache License 2.0 6 votes vote down vote up
static void createExampleTable() {
            
    
    // Provide the initial provisioned throughput values as Java long data types
    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
        .withReadCapacityUnits(5L)
        .withWriteCapacityUnits(6L);
    CreateTableRequest request = new CreateTableRequest()
        .withTableName(tableName)
        .withProvisionedThroughput(provisionedThroughput);
    
    ArrayList<AttributeDefinition> attributeDefinitions= new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName("Id").withAttributeType("N"));
    request.setAttributeDefinitions(attributeDefinitions);
    
    ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
    tableKeySchema.add(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH));
    request.setKeySchema(tableKeySchema);
  
    client.createTable(request);
    
    waitForTableToBecomeAvailable(tableName); 

    getTableInformation();
    
}
 
Example #17
Source File: DeviceAuthentication.java    From reinvent2013-mobile-photo-share with Apache License 2.0 6 votes vote down vote up
/**
 * Used to create the device table. This function only needs to be called
 * once.
 */
protected void createDeviceTable() throws DataAccessException {
    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
            .withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L);

    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName(
            ATTRIBUTE_UID).withAttributeType("S"));

    ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
    tableKeySchema.add(new KeySchemaElement().withAttributeName(ATTRIBUTE_UID)
            .withKeyType(KeyType.HASH));

    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(DEVICE_TABLE)
            .withProvisionedThroughput(provisionedThroughput)
            .withAttributeDefinitions(attributeDefinitions)
            .withKeySchema(tableKeySchema);

    try {
        ddb.createTable(createTableRequest);
    } catch (AmazonClientException e) {
        throw new DataAccessException("Failed to create table: " + DEVICE_TABLE, e);
    }
}
 
Example #18
Source File: DeviceAuthentication.java    From reinvent2013-mobile-photo-share with Apache License 2.0 6 votes vote down vote up
/**
 * Used to create the device table. This function only needs to be called
 * once.
 */
protected void createDeviceTable() throws DataAccessException {
    ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
            .withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L);

    ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
    attributeDefinitions.add(new AttributeDefinition().withAttributeName(
            ATTRIBUTE_UID).withAttributeType("S"));

    ArrayList<KeySchemaElement> tableKeySchema = new ArrayList<KeySchemaElement>();
    tableKeySchema.add(new KeySchemaElement().withAttributeName(ATTRIBUTE_UID)
            .withKeyType(KeyType.HASH));

    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(DEVICE_TABLE)
            .withProvisionedThroughput(provisionedThroughput)
            .withAttributeDefinitions(attributeDefinitions)
            .withKeySchema(tableKeySchema);

    try {
        ddb.createTable(createTableRequest);
    } catch (AmazonClientException e) {
        throw new DataAccessException("Failed to create table: " + DEVICE_TABLE, e);
    }
}
 
Example #19
Source File: DynamoDBOperations.java    From geowave with Apache License 2.0 6 votes vote down vote up
private boolean createTable(final String qName, final boolean dataIndexTable) {
  return createTable(
      qName,
      dataIndexTable
          ? () -> new CreateTableRequest().withTableName(qName).withAttributeDefinitions(
              new AttributeDefinition(
                  DynamoDBRow.GW_PARTITION_ID_KEY,
                  ScalarAttributeType.B)).withKeySchema(
                      new KeySchemaElement(DynamoDBRow.GW_PARTITION_ID_KEY, KeyType.HASH))
          : () -> new CreateTableRequest().withTableName(qName).withAttributeDefinitions(
              new AttributeDefinition(DynamoDBRow.GW_PARTITION_ID_KEY, ScalarAttributeType.B),
              new AttributeDefinition(
                  DynamoDBRow.GW_RANGE_KEY,
                  ScalarAttributeType.B)).withKeySchema(
                      new KeySchemaElement(DynamoDBRow.GW_PARTITION_ID_KEY, KeyType.HASH),
                      new KeySchemaElement(DynamoDBRow.GW_RANGE_KEY, KeyType.RANGE)));
}
 
Example #20
Source File: DynamoDBService.java    From Doradus with Apache License 2.0 6 votes vote down vote up
@Override
public void createStoreIfAbsent(String storeName, boolean bBinaryValues) {
    String tableName = storeToTableName(storeName);
    if (!Tables.doesTableExist(m_ddbClient, tableName)) {
        // Create a table with a primary hash key named '_key', which holds a string
        m_logger.info("Creating table: {}", tableName);
        CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName)
            .withKeySchema(new KeySchemaElement()
                .withAttributeName(ROW_KEY_ATTR_NAME)
                .withKeyType(KeyType.HASH))
            .withAttributeDefinitions(new AttributeDefinition()
                .withAttributeName(ROW_KEY_ATTR_NAME)
                .withAttributeType(ScalarAttributeType.S))
            .withProvisionedThroughput(new ProvisionedThroughput()
                .withReadCapacityUnits(READ_CAPACITY_UNITS)
                .withWriteCapacityUnits(WRITE_CAPACITY_UNITS));
        m_ddbClient.createTable(createTableRequest).getTableDescription();
        try {
            Tables.awaitTableToBecomeActive(m_ddbClient, tableName);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);  
        }
    }
}
 
Example #21
Source File: AmazonDynamoDBStubTest.java    From aws-java-sdk-stubs with Apache License 2.0 6 votes vote down vote up
private CreateTableResult createTable() throws Exception {
  List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
  AttributeDefinition attributeDefinition = new AttributeDefinition()
    .withAttributeName(TEST_ATTRIBUTE)
    .withAttributeType(ScalarAttributeType.S);
  attributeDefinitions.add(attributeDefinition);

  String tableName = TEST_TABLE_NAME;

  List<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>();
  KeySchemaElement keySchemaElement = new KeySchemaElement()
    .withAttributeName(TEST_ATTRIBUTE)
    .withKeyType(KeyType.HASH);

  ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput()
    .withReadCapacityUnits(UNITS)
    .withWriteCapacityUnits(UNITS);

  CreateTableResult result = dynamoDb.createTable(attributeDefinitions, tableName, keySchema, provisionedThroughput);

  return result;
}
 
Example #22
Source File: AutoGeneratedKeysITCase.java    From aws-dynamodb-encryption-java with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    DynamoDBMapperCryptoIntegrationTestBase.setUp();

    // Create a table
    String keyName = DynamoDBMapperCryptoIntegrationTestBase.KEY_NAME;
    String rangeKeyAttributeName = "rangeKey";

    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(TABLE_NAME)
            .withKeySchema(new KeySchemaElement().withAttributeName(keyName).withKeyType(KeyType.HASH),
                    new KeySchemaElement().withAttributeName(rangeKeyAttributeName).withKeyType(KeyType.RANGE))
            .withAttributeDefinitions(
                    new AttributeDefinition().withAttributeName(keyName).withAttributeType(
                            ScalarAttributeType.S),
                    new AttributeDefinition().withAttributeName(rangeKeyAttributeName).withAttributeType(
                            ScalarAttributeType.S));
    createTableRequest.setProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L));

    if (TableUtils.createTableIfNotExists(dynamo, createTableRequest)) {
        TableUtils.waitUntilActive(dynamo, TABLE_NAME);
    }
}
 
Example #23
Source File: MapperSaveConfigCryptoIntegrationTestBase.java    From aws-dynamodb-encryption-java with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    DynamoDBCryptoIntegrationTestBase.setUp();
    dynamoMapper = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo);

    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(tableName)
            .withKeySchema(new KeySchemaElement().withAttributeName(hashKeyName).withKeyType(KeyType.HASH))
            .withKeySchema(new KeySchemaElement().withAttributeName(rangeKeyName).withKeyType(KeyType.RANGE))
            .withAttributeDefinitions(new AttributeDefinition().withAttributeName(hashKeyName)
                    .withAttributeType(ScalarAttributeType.S))
            .withAttributeDefinitions(new AttributeDefinition().withAttributeName(rangeKeyName)
                    .withAttributeType(ScalarAttributeType.N));
    createTableRequest.setProvisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT);

    if (TableUtils.createTableIfNotExists(dynamo, createTableRequest)) {
        TableUtils.waitUntilActive(dynamo, tableName);
    }
}
 
Example #24
Source File: DynamoDBCryptoIntegrationTestBase.java    From aws-dynamodb-encryption-java with Apache License 2.0 6 votes vote down vote up
protected static void setUpTableWithRangeAttribute() throws Exception {
    setUp();

    String keyName = DynamoDBCryptoIntegrationTestBase.KEY_NAME;
    String rangeKeyAttributeName = "rangeKey";

    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(TABLE_WITH_RANGE_ATTRIBUTE)
            .withKeySchema(new KeySchemaElement().withAttributeName(keyName).withKeyType(KeyType.HASH),
                    new KeySchemaElement().withAttributeName(rangeKeyAttributeName).withKeyType(KeyType.RANGE))
            .withAttributeDefinitions(
                    new AttributeDefinition().withAttributeName(keyName).withAttributeType(
                            ScalarAttributeType.N),
                    new AttributeDefinition().withAttributeName(rangeKeyAttributeName).withAttributeType(
                            ScalarAttributeType.N));
    createTableRequest.setProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L));

    if (TableUtils.createTableIfNotExists(dynamo, createTableRequest)) {
        TableUtils.waitUntilActive(dynamo, TABLE_WITH_RANGE_ATTRIBUTE);
    }
}
 
Example #25
Source File: ScanITCase.java    From aws-dynamodb-encryption-java with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpTestData() throws Exception {
    String keyName = "id";
    CreateTableRequest createTableRequest = new CreateTableRequest()
            .withTableName(TABLE_NAME)
            .withKeySchema(new KeySchemaElement().withAttributeName(keyName).withKeyType(KeyType.HASH))
            .withAttributeDefinitions(
                    new AttributeDefinition().withAttributeName(keyName).withAttributeType(
                            ScalarAttributeType.S));
    createTableRequest.setProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(10L)
            .withWriteCapacityUnits(5L));

    TableUtils.createTableIfNotExists(dynamo, createTableRequest);
    TableUtils.waitUntilActive(dynamo, TABLE_NAME);

    createTestData();
}
 
Example #26
Source File: DynamoDBManagerTest.java    From aws-dynamodb-mars-json-demo with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateTableTableDoesNotExist() {
    final Collection<AttributeDefinition> ads = Arrays.asList(new AttributeDefinition("Hash", ScalarAttributeType.S));
    final Collection<KeySchemaElement> kses = Arrays.asList(new KeySchemaElement("Hash", KeyType.HASH));
    final TableDescription description = new TableDescription().withAttributeDefinitions(ads).withKeySchema(kses)
        .withTableName(tableName);
    final CreateTableResult cTR = new CreateTableResult().withTableDescription(description);
    EasyMock.expect(dynamoDB.describeTable(tableName)).andThrow(new ResourceNotFoundException(null));
    final CreateTableRequest request = new CreateTableRequest().withAttributeDefinitions(ads).withKeySchema(kses)
        .withTableName(tableName);
    EasyMock.expect(dynamoDB.createTable(request)).andReturn(cTR);
    PowerMock.replayAll();
    assertEquals(description, DynamoDBManager.createTable(dynamoDB, request));
    PowerMock.verifyAll();
}
 
Example #27
Source File: TransactionManagerDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 5 votes vote down vote up
@Override
public CreateTableResult createTable(
        List<AttributeDefinition> attributeDefinitions, String tableName,
        List<KeySchemaElement> keySchema,
        ProvisionedThroughput provisionedThroughput)
        throws AmazonServiceException, AmazonClientException {
    throw new UnsupportedOperationException("Use the underlying client instance instead");
}
 
Example #28
Source File: Aws1ITest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
private static void createTable(final AmazonDynamoDB dbClient, final String tableName) {
  final String partitionKeyName = tableName + "-pk";
  final CreateTableRequest createTableRequest = new CreateTableRequest()
    .withTableName(tableName)
    .withKeySchema(new KeySchemaElement().withAttributeName(partitionKeyName).withKeyType(KeyType.HASH))
    .withAttributeDefinitions(new AttributeDefinition().withAttributeName(partitionKeyName).withAttributeType("S"))
    .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(5L));
  dbClient.createTable(createTableRequest);
  System.out.println("Table " + tableName + " created");
}
 
Example #29
Source File: DynamoDBInstallAppContextStoreTest.java    From smartapp-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void initIsFineWithTableAlreadyExisting() {
    when(dynamoDB.createTable(eq("installedAppContext"),
            eq(Arrays.asList(new KeySchemaElement("installedAppId", KeyType.HASH))),
            eq(Arrays.asList(new AttributeDefinition("installedAppId", "S"))), any()))
                    .thenThrow(new ResourceInUseException("table already exists"));

    tester.init();

    verify(dynamoDB).createTable(eq("installedAppContext"),
            eq(Arrays.asList(new KeySchemaElement("installedAppId", KeyType.HASH))),
            eq(Arrays.asList(new AttributeDefinition("installedAppId", "S"))), any());
}
 
Example #30
Source File: AwsTest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
private static void createTable(final AmazonDynamoDB dbClient, final String tableName) {
  final String partitionKeyName = tableName + "Id";
  final CreateTableRequest createTableRequest = new CreateTableRequest()
    .withTableName(tableName)
    .withKeySchema(new KeySchemaElement().withAttributeName(partitionKeyName).withKeyType(KeyType.HASH))
    .withAttributeDefinitions(new AttributeDefinition().withAttributeName(partitionKeyName).withAttributeType("S"))
    .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(5L));

  dbClient.createTable(createTableRequest);
}