Недавно я меняю код для перехода с версии v2 на v4 Amazon S3.Делая это изменение, я узнал, что класс Key больше не присутствует.И в одном из постов меня попросили сменить ключ на карту, и теперь я получаю исключения при создании запроса на получение элемента партии.
Исключение
Caused by: com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: The provided key element does not match the schema (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: L7J3ERURVAS0TRV4M1UV2GL09NVV4KQNSO5AEMVJF66Q9ASUAAJG)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1701)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1356)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1102)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:759)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:733)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:715)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:675)
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:657)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:521)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.doInvoke(AmazonDynamoDBClient.java:4230)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:4197)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.executeBatchGetItem(AmazonDynamoDBClient.java:509)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.batchGetItem(AmazonDynamoDBClient.java:476)
at com.example.anomalytics.DynamoDbStore.getAll(DynamoDbStore.java:156)
at com.example.anomalytics.CachedStore.getAll(CachedStore.java:97)
at com.example.anomalytics.Mapper.getEncryptedEntries(Mapper.java:45)
at com.example.anomalytics.Mapper.getAndDecryptEntries(Mapper.java:50)
at com.example.anomalytics.MapResource.getEntries(MapResource.java:48)
at com.example.anomalytics.MapResource.getEntries(MapResource.java:80)
Старый код
ImmutableSet.Builder<Map<String, AttributeValue>> keyBuilder = ImmutableSet.builder();
for (CompositeKey key : keys) {
keyBuilder.add(dynamoKey(key));
}
KeysAndAttributes requestKeys = new KeysAndAttributes().withKeys(keyBuilder.build());
BatchGetItemRequest request = new BatchGetItemRequest().withRequestItems(ImmutableMap.of(tableName, requestKeys));
private static Map<String, AttributeValue> dynamoKey(CompositeKey key)
{
return new Key().withHashKeyElement(new AttributeValue().withS(key.getKey()));;
}
Новый код
ImmutableSet.Builder<Map<String, AttributeValue>> keyBuilder = ImmutableSet.builder();
for (CompositeKey key : keys) {
keyBuilder.add(dynamoKey(key));
}
KeysAndAttributes requestKeys = new KeysAndAttributes().withKeys(keyBuilder.build());
BatchGetItemRequest request = new BatchGetItemRequest().withRequestItems(ImmutableMap.of(tableName, requestKeys));
private static Map<String, AttributeValue> dynamoKey(CompositeKey key)
{
Map<String, AttributeValue> map = new HashMap<>();
map.put(key.getKey(), new AttributeValue().withS(key.getKey()));
return map;
}
Пожалуйста, помогите.