Search code examples
amazon-dynamodb

What is the alternative for AmazonDynamoDBClient that got deprecated?


Does anyone know what has replaced AmazonDynamoDBClient? Couldn't find anything in the documentation

Package - com.amazonaws.services.dynamodbv2

    AmazonDynamoDBClient amazonDynamoDBClient = new AmazonDynamoDBClient();

Solution

  • As per the API doc, the builder class (e.g. AmazonDynamoDBClientBuilder) should be used to create the instance.

    Sample code using the builder class:-

    I have create the client for DynamoDB local.

    DynamoDB dynamoDB = new DynamoDB(AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(new EndpointConfiguration("http://localhost:8000", "us-east-1")).build());
    
    Table table = dynamoDB.getTable("Movies");
    

    Scan using DynamoDB table class:-

    private static void findProductsForPriceLessThanZero() {
    
            Table table = dynamoDB.getTable(tableName);
    
            Map<String, Object> expressionAttributeValues = new HashMap<String, Object>();
            expressionAttributeValues.put(":pr", 100);
    
            ItemCollection<ScanOutcome> items = table.scan(
                "Price < :pr", //FilterExpression
                "Id, Title, ProductCategory, Price", //ProjectionExpression
                null, //ExpressionAttributeNames - not used in this example 
                expressionAttributeValues);
    
            System.out.println("Scan of " + tableName + " for items with a price less than 100.");
            Iterator<Item> iterator = items.iterator();
            while (iterator.hasNext()) {
                System.out.println(iterator.next().toJSONPretty());
            }    
        }