通过仅指定索引键,从具有范围键的 DynamoDB 表中检索项目

ens*_*are 5 python boto amazon-dynamodb

我有一个带有主键和范围键集的表:

user_id
timestamp_joined
Run Code Online (Sandbox Code Playgroud)

使用 boto api 层,是否可以通过指定 user_id(不带范围键)来检索项目?每次我在没有指定范围键的情况下执行 getItem() 查询时,它都会失败。我只能通过指定范围键(timestamp_joined)来让它工作。

仅通过 user_id 获取时的错误消息如下:

boto.exception.DynamoDBResponseError: DynamoDBResponseError: 400 Bad Request 
{'message': 'One or more parameter values were invalid: The provided 
key size does ot match with that of the schema', '__type':
'com.amazon.coral.validate#ValidationException'} 
Run Code Online (Sandbox Code Playgroud)

gar*_*aat 3

听起来您想执行查询。您可以仅指定 user_id(哈希键)来查询表,并且查询将返回与该 user_id 匹配的所有项目,无论范围值如何。

  • 在不指定范围键的情况下执行 get_item 的唯一方法是表的架构不包含范围键。因此,如果时间戳作为辅助键没有用,我不会将其包含在架构中。 (3认同)