我在 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 是主分区键的名称。
关于可能的原因或修复的任何想法?