如何使用Amazon模块获取只匹配分区键(表有排序键)的所有项。我使用GetItemRequest查询没有排序键。
GetItemRequest getItemRequest = getRequest(externalId);
IDMapping.from(dynamoDB.getItem(getItemRequest).item());当我只使用GetItemRequest分区键进行查询时,会得到以下错误。
Caused by: software.amazon.awssdk.services.dynamodb.model.DynamoDbException: The provided key element does not match the schema (Service: DynamoDb, Status Code: 400, Request ID: 6C9BTJCJOTS7I5FI1EBJLIQK3RVV4KQNSO5AEMVJF66Q9ASUAAJG, Extended Request ID: null)
我在夸克应用程序中使用以下依赖项。
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>dynamodb</artifactId>
</dependency>这个查询可以使用aws cli、aws控制台,也可以使用旧的java。
有什么办法可以克服这个问题吗?
提前谢谢
发布于 2021-12-10 09:14:32
GetItem请求需要完整的密钥(分区和排序)。你可以用查询请求做你想做的事。
HashMap<String, String> nameMap = new HashMap<String, String>();
nameMap.put("#yr", "year");
HashMap<String, Object> valueMap = new HashMap<String, Object>();
valueMap.put(":yyyy", 1985);
QuerySpec querySpec = new QuerySpec().withKeyConditionExpression("#yr = :yyyy").withNameMap(nameMap)
.withValueMap(valueMap);
items = table.query(querySpec);此示例用于具有复合键的表:
https://stackoverflow.com/questions/70292785
复制相似问题