Java Code Examples for com.amazonaws.services.dynamodbv2.AmazonDynamoDB#putItem()

The following examples show how to use com.amazonaws.services.dynamodbv2.AmazonDynamoDB#putItem() . 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: StreamsAdapterDemoHelper.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 2
Source File: DynamoDBWorkerUtilsTest.java    From aws-dynamodb-mars-json-demo with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateETag() {
    AmazonDynamoDB dynamoDB = PowerMock.createMock(AmazonDynamoDB.class);
    Map<String, AttributeValue> newItem = new HashMap<String, AttributeValue>();
    newItem.put(MarsDynamoDBManager.RESOURCE_TABLE_HASH_KEY, new AttributeValue(resource));
    newItem.put(DynamoDBWorkerUtils.ETAG_KEY, new AttributeValue(eTag));
    dynamoDB.putItem(table, newItem);
    PowerMock.expectLastCall().andReturn(null);
    PowerMock.replayAll();
    DynamoDBWorkerUtils.updateETag(dynamoDB, table, resource, eTag);
    PowerMock.verifyAll();
}
 
Example 3
Source File: ITTracingRequestHandler.java    From zipkin-aws with Apache License 2.0 4 votes vote down vote up
@Override protected void post(AmazonDynamoDB dynamoDB, String s, String s1) {
  dynamoDB.putItem(s, Collections.emptyMap());
}
 
Example 4
Source File: StreamsAdapterDemoHelper.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 5
Source File: DynamoDBWorkerUtils.java    From aws-dynamodb-mars-json-demo with Apache License 2.0 3 votes vote down vote up
/**
 * Updates the resource table for the specified resource with the specified ETag.
 *
 * @param dynamoDB
 *            DynamoDB client configured with a region and credentials
 * @param table
 *            The DynamoDB resource table
 * @param resource
 *            The resource URL
 * @param eTag
 *            The new ETag for the resource
 */
public static void updateETag(final AmazonDynamoDB dynamoDB, final String table, final String resource,
    final String eTag) {
    // Build item
    final Map<String, AttributeValue> newResource = new HashMap<>();
    newResource.put(MarsDynamoDBManager.RESOURCE_TABLE_HASH_KEY, new AttributeValue(resource));
    newResource.put(DynamoDBWorkerUtils.ETAG_KEY, new AttributeValue(eTag));
    dynamoDB.putItem(table, newResource);
}