【发布时间】:2020-02-24 15:30:13
【问题描述】:
我在 DynamoDB 中创建了一个表,该表同时具有主键(字符串)和排序键(数字)(课程-课程-id),我正在使用以下简单的 Lambda 函数来查询课程所在的表 -课程 ID > 0:
import json
import boto3
from boto3.dynamodb.conditions import Key, Attr
#always start with the lambda_handler
def lambda_handler(event, context):
# make the connection to dynamodb
dynamodb = boto3.resource('dynamodb')
# select the table
table = dynamodb.Table("table-name")
response = table.query(
KeyConditionExpression=Key('course-lesson-id').gt(0)
)
items = response['Items']
print(items)
据我了解,结果应该根据排序键按数字顺序返回,但我收到以下错误:
ClientError: An error occurred (ValidationException) when calling the
Query operation: Query condition missed key schema element: course-
lesson
course-lesson 是主分区键的名称。
对可能的原因或解决方法有什么想法吗?
【问题讨论】:
-
看起来它返回的值首先按
Key排序,然后是Sort Key。 -
不,它不是按分区键排序的,因为它在执行扫描时不用于此类。
标签: aws-lambda amazon-dynamodb