【发布时间】:2021-10-20 05:08:47
【问题描述】:
我正在使用 Lambda Python 并使用查询 KeyConditionExpression 从 DynamodDB 获取记录。 我想按特定字段(createdAt(时间戳))排序,但不工作。 这是我的代码:
import json
import boto3
from boto3.dynamodb.conditions import Key
def lambda_handler(event, context):
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('mytable')
resp = table.query(
IndexName='empid-template_for-index',
KeyConditionExpression=
Key('template_for').eq('mytemplate') & Key('empid').eq('myempid'),
Limit=10,
ScanIndexForward=False,
)
print(resp)
你能帮我吗,我怎样才能按字段 createdAt 的降序获得前 10 条记录?
【问题讨论】:
-
可以分享一下你表的分区键和排序键吗?
-
@stijndepestel 表的分区键是“query_id”并且未定义排序键。对于上述查询创建的索引,分区键为“empid”,排序键为“template_for”,我想要相同的键条件,但想使用创建的字段进行排序。
标签: python-3.x aws-lambda amazon-dynamodb