use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project aws-doc-sdk-examples by awsdocs.
the class StreamsAdapterDemoHelper method putItem.
public static void putItem(AmazonDynamoDB dynamoDBClient, String tableName, java.util.Map<String, AttributeValue> items) {
PutItemRequest putItemRequest = new PutItemRequest().withTableName(tableName).withItem(items);
dynamoDBClient.putItem(putItemRequest);
}
use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project aws-doc-sdk-examples by awsdocs.
the class StreamsAdapterDemoHelper method putItem.
public static void putItem(AmazonDynamoDB dynamoDBClient, String tableName, String id, String val) {
java.util.Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
item.put("Id", new AttributeValue().withN(id));
item.put("attribute-1", new AttributeValue().withS(val));
PutItemRequest putItemRequest = new PutItemRequest().withTableName(tableName).withItem(item);
dynamoDBClient.putItem(putItemRequest);
}
use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project aws-doc-sdk-examples by awsdocs.
the class StreamsAdapterDemoHelper method createTable.
/**
* @return StreamArn
*/
public static String createTable(AmazonDynamoDB 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>();
// Partition
keySchema.add(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH));
// key
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();
}
}
use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project aws-doc-sdk-examples by awsdocs.
the class MoviesCreateTable method main.
public static void main(String[] args) throws Exception {
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", "us-west-2")).build();
DynamoDB dynamoDB = new DynamoDB(client);
String tableName = "Movies";
try {
System.out.println("Attempting to create table; please wait...");
Table table = dynamoDB.createTable(tableName, // Partition
Arrays.asList(// Partition
new KeySchemaElement("year", KeyType.HASH), // key
new KeySchemaElement("title", // Sort key
KeyType.RANGE)), Arrays.asList(new AttributeDefinition("year", ScalarAttributeType.N), new AttributeDefinition("title", ScalarAttributeType.S)), new ProvisionedThroughput(10L, 10L));
table.waitForActive();
System.out.println("Success. Table status: " + table.getDescription().getTableStatus());
} catch (Exception e) {
System.err.println("Unable to create table: ");
System.err.println(e.getMessage());
}
}
use of com.amazonaws.services.dynamodbv2.AmazonDynamoDB in project aws-doc-sdk-examples by awsdocs.
the class MoviesItemOps01 method main.
public static void main(String[] args) throws Exception {
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", "us-west-2")).build();
DynamoDB dynamoDB = new DynamoDB(client);
Table table = dynamoDB.getTable("Movies");
int year = 2015;
String title = "The Big New Movie";
final Map<String, Object> infoMap = new HashMap<String, Object>();
infoMap.put("plot", "Nothing happens at all.");
infoMap.put("rating", 0);
try {
System.out.println("Adding a new item...");
PutItemOutcome outcome = table.putItem(new Item().withPrimaryKey("year", year, "title", title).withMap("info", infoMap));
System.out.println("PutItem succeeded:\n" + outcome.getPutItemResult());
} catch (Exception e) {
System.err.println("Unable to add item: " + year + " " + title);
System.err.println(e.getMessage());
}
}
Aggregations