user7399250
user7399250

Reputation:

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();

Upvotes: 11

Views: 11812

Answers (2)

Rene Enriquez
Rene Enriquez

Reputation: 1599

I am using spring-boot, the way I am working with Dynamo is injecting an AWSCredentialsProvider and using the variables which are in my environment in this way:

@Bean
public AmazonDynamoDB amazonDynamoDB(AWSCredentialsProvider awsCredentialsProvider) {
    AmazonDynamoDB amazonDynamoDB
            = AmazonDynamoDBClientBuilder.standard()
            .withCredentials(awsCredentialsProvider).build();
    return amazonDynamoDB;
}

@Bean
public AWSCredentialsProvider awsCredentialsProvider() {
    return new EnvironmentVariableCredentialsProvider();
}

The full example is available here: https://github.com/ioet/bpm-skills-api

Upvotes: 3

notionquest
notionquest

Reputation: 39166

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());
        }    
    }

Upvotes: 18

Related Questions