Hello,
I'm using the below java code to get from DynamoDB all the items for a Partition Key. Table has a Partition Key (PK) and a Sort Key (SK) that are Strings.
TableKeysAndAttributes tableKeysAndAttributes = new TableKeysAndAttributes(tableDetails.getTableName())
.withHashOnlyKeys(tableDetails.getTablePKName(), tableDetails.getTablePKValue())
.withProjectionExpression("document");
BatchGetItemOutcome outcome = dynamoClient.batchGetItem(tableKeysAndAttributes);
I got the below error, as in the case when I should send also the SK to the database, while the API supports only PK:
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:
LGT808CBEEL6CEN8EMATK07R0JVV4KQNSO5AEMVJF66Q9ASUAAJG; Proxy: null): java.lang.RuntimeException java.lang.RuntimeException: 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:
LGT808CBEEL6CEN8EMATK07R0JVV4KQNSO5AEMVJF66Q9ASUAAJG; Proxy: null) at
com.amazonaws.lambda.mihai.translate.handler.LambdaFunctionHandler.handleRequest(LambdaFunctionHandler.java:79) at
com.amazonaws.lambda.mihai.translate.handler.LambdaFunctionHandler.handleRequest(LambdaFunctionHandler.java:26) 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:
LGT808CBEEL6CEN8EMATK07R0JVV4KQNSO5AEMVJF66Q9ASUAAJG; Proxy: null) at
com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1879) at
com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleServiceErrorResponse(AmazonHttpClient.java:1418) at
com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1387) at
com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1157) at
com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:814) at
com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:781) at
com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:755) at
com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:715) at
com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:697) at
com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:561) at
com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:541) at
com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.doInvoke(AmazonDynamoDBClient.java:6999) at
com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:6966) at
com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.executeBatchGetItem(AmazonDynamoDBClient.java:607) at
com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.batchGetItem(AmazonDynamoDBClient.java:571) at
com.amazonaws.services.dynamodbv2.document.internal.BatchGetItemImpl.doBatchGetItem(BatchGetItemImpl.java:98) at
com.amazonaws.services.dynamodbv2.document.internal.BatchGetItemImpl.batchGetItem(BatchGetItemImpl.java:57) at
com.amazonaws.services.dynamodbv2.document.DynamoDB.batchGetItem(DynamoDB.java:153) at
com.amazonaws.lambda.mihai.servicecommons.service.DynamoAbstractService.getPartitionKeyDocuments(DynamoAbstractService.java:229) at
Could you please specify why do I have the error in this case ?
Thank you,
Mihai ADAM
In the described case (with PK and SK) is it possible to get all records for one PK, using the standard interface, and without using a Query ?
Which is the best solution to get all records for a PK ?
Thank you