@Override public CreateTableResult createTable(java.util.List<AttributeDefinition> attributeDefinitions, String tableName, java.util.List<KeySchemaElement> keySchema, ProvisionedThroughput provisionedThroughput) { return createTable(new CreateTableRequest().withAttributeDefinitions(attributeDefinitions).withTableName(tableName).withKeySchema(keySchema) .withProvisionedThroughput(provisionedThroughput)); }
@PostConstruct public void setup() { try { DescribeTableResult result = dynamoDBClient.describeTable(tableConfig.getTableName()); if (!result.getTable().getKeySchema().equals(PROJECT_KEYSCHEMA) || !ImmutableSet.copyOf(result.getTable().getAttributeDefinitions()).equals(ATTRIBUTES)) { throw new IllegalStateException("Invalid schema for user storage dynamodb table. " + "Please remove existing table or change dynamodb table."); } } catch (ResourceNotFoundException e) { dynamoDBClient.createTable(new CreateTableRequest().withTableName(tableConfig.getTableName()) .withKeySchema(PROJECT_KEYSCHEMA) .withAttributeDefinitions(ATTRIBUTES) .withProvisionedThroughput(new ProvisionedThroughput() .withReadCapacityUnits(3L) .withWriteCapacityUnits(3L))); } }
private void createTable() { dynamoDBClient.createTable(new CreateTableRequest() .withTableName(tableConfig.getTableName()).withKeySchema(PROJECT_KEYSCHEMA) .withAttributeDefinitions(ATTRIBUTES) .withProvisionedThroughput(new ProvisionedThroughput() .withReadCapacityUnits(1L) .withWriteCapacityUnits(1L))); }
private void createTable() { dynamoDBClient.createTable(new CreateTableRequest() .withTableName(tableConfig.getTableName()).withKeySchema(PROJECT_KEYSCHEMA) .withAttributeDefinitions(ATTRIBUTES) .withProvisionedThroughput(new ProvisionedThroughput() .withReadCapacityUnits(1L) .withWriteCapacityUnits(1L))); }
createTableRequest.setKeySchema(keySchema); createTableRequest.setProvisionedThroughput(provisionedThroughput); return createTable(createTableRequest);
private void createTable() { dynamoDBClient.createTable(new CreateTableRequest() .withTableName(tableConfig.getTableName()).withKeySchema(PROJECT_KEYSCHEMA) .withAttributeDefinitions(ATTRIBUTES) .withStreamSpecification(new StreamSpecification().withStreamEnabled(true).withStreamViewType(StreamViewType.NEW_IMAGE)) .withProvisionedThroughput(new ProvisionedThroughput() .withReadCapacityUnits(1L) .withWriteCapacityUnits(1L))); }
public static void main(String [] args) { AmazonDynamoDBClient client = new AmazonDynamoDBClient(new BasicAWSCredentials("akey1", "skey1")); client.setEndpoint("http://localhost:8000"); DynamoDBMapper mapper = new DynamoDBMapper(client); client.createTable(new CreateTableRequest() .withTableName("nested-data-test") .withAttributeDefinitions(new AttributeDefinition().withAttributeName("desc").withAttributeType("S")) .withKeySchema(new KeySchemaElement().withKeyType("HASH").withAttributeName("desc")) .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L))); NestedData u = new NestedData(); u.setDesc("else"); Map<String, String> c = new HashMap<String, String>(); c.put("type", "some"); u.setConf(c); mapper.save(u); DynamoDBQueryExpression<NestedData> queryExpression = new DynamoDBQueryExpression<NestedData>(); queryExpression.withHashKeyValues(u); queryExpression.withFilterExpression("conf.#t = :type") .addExpressionAttributeNamesEntry("#t", "type") // returns nothing if use "Type" .addExpressionAttributeValuesEntry(":type", new AttributeValue("some")); for(NestedData u2 : mapper.query(NestedData.class, queryExpression)) { System.out.println(u2.getDesc()); // "else" } }
@Override public CreateTableResult createTable(java.util.List<AttributeDefinition> attributeDefinitions, String tableName, java.util.List<KeySchemaElement> keySchema, ProvisionedThroughput provisionedThroughput) { return createTable(new CreateTableRequest().withAttributeDefinitions(attributeDefinitions).withTableName(tableName).withKeySchema(keySchema) .withProvisionedThroughput(provisionedThroughput)); }
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)); 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); } }
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(); }
.withAttributeDefinitions(attributeDefinitions); client.createTable(request);
/** * @return StreamArn */ public static String createTable(AmazonDynamoDBClient client, String tableName) { java.util.List<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>(); attributeDefinitions.add(new AttributeDefinition().withAttributeName("Id").withAttributeType("N")); java.util.List<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>(); keySchema.add(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH)); ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput() .withReadCapacityUnits(2L).withWriteCapacityUnits(2L); StreamSpecification streamSpecification = new StreamSpecification(); streamSpecification.setStreamEnabled(true); streamSpecification.setStreamViewType(StreamViewType.NEW_IMAGE); CreateTableRequest createTableRequest = new CreateTableRequest() .withTableName(tableName) .withAttributeDefinitions(attributeDefinitions) .withKeySchema(keySchema) .withProvisionedThroughput(provisionedThroughput) .withStreamSpecification(streamSpecification); try { System.out.println("Creating table " + tableName); CreateTableResult result = client.createTable(createTableRequest); return result.getTableDescription().getLatestStreamArn(); } catch(ResourceInUseException e) { System.out.println("Table already exists."); return describeTable(client, tableName).getTable().getLatestStreamArn(); } }
/** * Creates a table in AWS DynamoDB. * @param appid name of the {@link com.erudika.para.core.App} * @param readCapacity read capacity * @param writeCapacity write capacity * @return true if created */ public static boolean createTable(String appid, Long readCapacity, Long writeCapacity) { if (StringUtils.isBlank(appid) || StringUtils.containsWhitespace(appid) || existsTable(appid)) { return false; } try { getClient().createTable(new CreateTableRequest().withTableName(getTablNameForAppid(appid)). withKeySchema(new KeySchemaElement(Config._KEY, KeyType.HASH)). withAttributeDefinitions(new AttributeDefinition().withAttributeName(Config._KEY). withAttributeType(ScalarAttributeType.S)). withProvisionedThroughput(new ProvisionedThroughput(readCapacity, writeCapacity))); } catch (Exception e) { logger.error(null, e); return false; } return true; }
System.out.println(client.createTable(createTableRequest)); waitForTableToBecomeAvailable(tableName);
dynamoDBClient.createTable(createTableRequest);
@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); } } }
public static void createSessionTable(AmazonDynamoDBClient dynamo, String tableName, long readCapacityUnits, long writeCapacityUnits) { CreateTableRequest request = new CreateTableRequest().withTableName(tableName); request.withKeySchema(new KeySchemaElement().withAttributeName(DynamoSessionItem.SESSION_ID_ATTRIBUTE_NAME) .withKeyType(KeyType.HASH)); request.withAttributeDefinitions( new AttributeDefinition().withAttributeName(DynamoSessionItem.SESSION_ID_ATTRIBUTE_NAME) .withAttributeType(ScalarAttributeType.S)); request.setProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(readCapacityUnits) .withWriteCapacityUnits(writeCapacityUnits)); dynamo.createTable(request); }
.withReadCapacityUnits(m_readCapacityUnits) .withWriteCapacityUnits(m_writeCapacityUnits)); m_client.createTable(createTableRequest); try { Tables.awaitTableToBecomeActive(m_client, table);
System.out.println(client.createTable(createTableRequest)); waitForTableToBecomeAvailable(tableName);