Search in sources :

Example 26 with DynamoDbClient

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

the class SyncPagination method autoPagination.

public static void autoPagination(DynamoDbClient client) {
    System.out.println("running AutoPagination...\n");
    ListTablesRequest listTablesRequest = ListTablesRequest.builder().limit(3).build();
    ListTablesIterable responses = client.listTablesPaginator(listTablesRequest);
    System.out.println("AutoPagination: using for loop");
    for (final ListTablesResponse response : responses) {
        System.out.println(response.tableNames());
    }
    // Print the table names using the responses stream
    System.out.println("AutoPagination: using stream");
    responses.stream().forEach(response -> System.out.println(response.tableNames()));
    // Convert the stream of responses to stream of table names, then print the table names
    System.out.println("AutoPagination: using flatmap to get stream of table names");
    responses.stream().flatMap(response -> response.tableNames().stream()).forEach(System.out::println);
    System.out.println("AutoPagination: iterating directly on the table names");
    Iterable<String> tableNames = responses.tableNames();
    tableNames.forEach(System.out::println);
}
Also used : DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) ListTablesRequest(software.amazon.awssdk.services.dynamodb.model.ListTablesRequest) DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException) Region(software.amazon.awssdk.regions.Region) ListTablesResponse(software.amazon.awssdk.services.dynamodb.model.ListTablesResponse) ListTablesIterable(software.amazon.awssdk.services.dynamodb.paginators.ListTablesIterable) ListTablesIterable(software.amazon.awssdk.services.dynamodb.paginators.ListTablesIterable) ListTablesRequest(software.amazon.awssdk.services.dynamodb.model.ListTablesRequest) ListTablesResponse(software.amazon.awssdk.services.dynamodb.model.ListTablesResponse)

Example 27 with DynamoDbClient

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

the class SyncPagination method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    SyncPagination <type>\n\n" + "Where:\n" + "    type - the type of pagination. (auto, manual, or default). \n\n";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String type = args[0];
    Region region = Region.US_EAST_1;
    DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
    switch(type.toLowerCase()) {
        case "manual":
            manualPagination(ddb);
            break;
        case "auto":
            autoPagination(ddb);
            autoPaginationWithResume(ddb);
            break;
        default:
            manualPagination(ddb);
            autoPagination(ddb);
            autoPaginationWithResume(ddb);
    }
    ddb.close();
}
Also used : DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) Region(software.amazon.awssdk.regions.Region)

Example 28 with DynamoDbClient

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

the class EnhancedGetItem 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 = getItem(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 29 with DynamoDbClient

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

the class EnhancedPutItem 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();
    putRecord(enhancedClient);
    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 30 with DynamoDbClient

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

the class CreateTableCompositeKey method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    <tableName>\n\n" + "Where:\n" + "    tableName - the Amazon DynamoDB table to create (for example, Music3).\n\n";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String tableName = args[0];
    Region region = Region.US_EAST_1;
    DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
    System.out.format("Creating Amazon DynamoDB table %s\n with a composite primary key:\n", tableName);
    System.out.format("* Language - partition key\n");
    System.out.format("* Greeting - sort key\n");
    String tableId = createTableComKey(ddb, tableName);
    System.out.println("The Amazon DynamoDB table Id value is " + tableId);
    ddb.close();
}
Also used : DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) Region(software.amazon.awssdk.regions.Region)

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