有谁知道什么取代了 AmazonDynamoDBClient? 在文档中找不到任何内容
软件包 - com.amazonaws.services.dynamodbv2
AmazonDynamoDBClient amazonDynamoDBClient = new AmazonDynamoDBClient();
根据 API 文档,应使用构建器类(例如
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());
}
}
我正在使用 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