不推荐使用的AmazonDynamoDBClient的替代方案是什么?

时间:2017-01-25 11:12:29

标签: amazon-dynamodb

有谁知道什么取代了AmazonDynamoDBClient? 无法在文档中找到任何内容

包 - com.amazonaws.services.dynamodbv2

    AmazonDynamoDBClient amazonDynamoDBClient = new AmazonDynamoDBClient();

2 个答案:

答案 0 :(得分:12)

根据API doc,构建器类(例如AmazonDynamoDBClientBuilder)应该用于创建实例。

使用构建器类的示例代码: -

我已为DynamoDB本地创建客户端。

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

Table table = dynamoDB.getTable("Movies");

使用DynamoDB表类扫描: -

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

答案 1 :(得分:1)

我正在使用spring-boot,与Dynamo一起工作的方式是注入AWSCredentialsProvider并以这种方式使用环境中的变量:

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

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

完整的示例可在此处找到:https://github.com/ioet/bpm-skills-api