I have created a table in DynamoDB that has both a primary key(string) and a sort key(number)(course-lesson-id) and I am using the following simple Lambda function to query the table where the course-lesson-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)
As I understand it, the results are supposed to be returned in numeric order based on the sort key, but I am getting the following error:
ClientError: An error occurred (ValidationException) when calling the
Query operation: Query condition missed key schema element: course-
lesson
course-lesson is the name of the primary partition key.
Any thoughts on possible causes or fixes?
Key
first, thenSort Key
. – John Rotenstein