Search in sources :

Example 31 with DynamoDbClient

use of software.amazon.awssdk.services.dynamodb.DynamoDbClient in project aws-doc-sdk-examples by awsdocs.

the class EnhancedModifyItem method main.

public static void main(String[] args) {
    String usage = "Usage:\n" + "    <key> <email> \n\n" + "Where:\n" + "    key - the name of the key in the table (id120).\n" + "    email - the value of the modified email column.\n";
    if (args.length != 2) {
        System.out.println(usage);
        System.exit(1);
    }
    String key = args[0];
    String email = args[1];
    Region region = Region.US_EAST_1;
    DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
    DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(ddb).build();
    String updatedValue = modifyItem(enhancedClient, key, email);
    System.out.println("The updated name value is " + updatedValue);
    ddb.close();
}
Also used : DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) Region(software.amazon.awssdk.regions.Region) DynamoDbEnhancedClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)

Example 32 with DynamoDbClient

use of software.amazon.awssdk.services.dynamodb.DynamoDbClient in project aws-doc-sdk-examples by awsdocs.

the class EnhancedQueryRecords method main.

public static void main(String[] args) {
    Region region = Region.US_EAST_1;
    DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
    DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder().dynamoDbClient(ddb).build();
    String result = queryTable(enhancedClient);
    System.out.println(result);
    ddb.close();
}
Also used : DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) Region(software.amazon.awssdk.regions.Region) DynamoDbEnhancedClient(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)

Example 33 with DynamoDbClient

use of software.amazon.awssdk.services.dynamodb.DynamoDbClient in project aws-doc-sdk-examples by awsdocs.

the class EnhancedScanRecordsWithExpression method main.

public static void main(String[] args) {
    String tableName = "Issues";
    System.out.format("Creating table \"%s\" with a simple primary key: \"Name\".\n", tableName);
    Region region = Region.US_EAST_1;
    DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
    createTable(ddb, tableName);
    loadData(ddb, tableName);
    scanIndex(ddb, tableName, "CreateDateIndex");
    scanUsingContains(ddb, tableName, "CreateDateIndex");
    queryIndex(ddb, tableName, "CreateDateIndex");
    ddb.close();
}
Also used : DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) Region(software.amazon.awssdk.regions.Region)

Example 34 with DynamoDbClient

use of software.amazon.awssdk.services.dynamodb.DynamoDbClient in project aws-doc-sdk-examples by awsdocs.

the class DynamoDBService method getClient.

private DynamoDbClient getClient() {
    // Create a DynamoDbClient object.
    Region region = Region.US_EAST_1;
    DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
    return ddb;
}
Also used : DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) Region(software.amazon.awssdk.regions.Region)

Example 35 with DynamoDbClient

use of software.amazon.awssdk.services.dynamodb.DynamoDbClient in project aws-doc-sdk-examples by awsdocs.

the class DynamoDBService method getItem.

// Get a single item from the Work table based on the Key.
public String getItem(String idValue) {
    DynamoDbClient ddb = getClient();
    String status = "";
    String description = "";
    HashMap<String, AttributeValue> keyToGet = new HashMap<String, AttributeValue>();
    keyToGet.put("id", AttributeValue.builder().s(idValue).build());
    // Create a GetItemRequest object.
    GetItemRequest request = GetItemRequest.builder().key(keyToGet).tableName("Work").build();
    try {
        Map<String, AttributeValue> returnedItem = ddb.getItem(request).item();
        // Get keys and values and get description and status.
        for (Map.Entry<String, AttributeValue> entry : returnedItem.entrySet()) {
            String k = entry.getKey();
            AttributeValue v = entry.getValue();
            if (k.compareTo("description") == 0) {
                description = v.s();
            } else if (k.compareTo("status") == 0) {
                status = v.s();
            }
        }
        return convertToString(toXmlItem(idValue, description, status));
    } catch (DynamoDbException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    return "";
}
Also used : DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient)

Aggregations

DynamoDbClient (software.amazon.awssdk.services.dynamodb.DynamoDbClient)40 Region (software.amazon.awssdk.regions.Region)32 DynamoDbEnhancedClient (software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient)13 DynamoDbException (software.amazon.awssdk.services.dynamodb.model.DynamoDbException)5 Instant (java.time.Instant)2 LocalDateTime (java.time.LocalDateTime)2 List (java.util.List)2 Map (java.util.Map)2 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)2 Segment (com.amazonaws.xray.entities.Segment)1 Subsegment (com.amazonaws.xray.entities.Subsegment)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 UtilityClass (lombok.experimental.UtilityClass)1 Slf4j (lombok.extern.slf4j.Slf4j)1 lombok.val (lombok.val)1