我有一个 API 网关 GET
端点,它扫描 DynamoDB 表并根据 Limit 参数检索结果:
requestTemplates:
application/json: >-
{
"TableName": "employee",
"Limit": 2
}
它正常工作,当我发送 limit = 2
时,此请求的响应是:
{
"Count":2,
"Items":[
{
"id":{
"S":"18"
},
"department":{
"S":"sales"
},
"name":{
"S":"Roger"
}
},
{
"id":{
"S":"16"
},
"department":{
"S":"technology"
},
"name":{
"S":"Petterson"
}
}
],
"LastEvaluatedKey":{
"id":{
"S":"16"
}
},
"ScannedCount":2
}
问题是:我在这个表中存储了 20 条记录,ScannedCount
和 Count
都等于 2。
为了使分页前端组件正常工作,我真的需要知道我存储的记录总数。
我查看了文档,发现此请求的预期结果为 ScannedCount = 2
和 Count = 20
。
有没有办法得到它?非常感谢。
最佳答案
如果您只有直接集成 api-gw <-> dynamodb 集成,请检查描述 - https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DescribeTable.html并进行两次调用以获取所需的数据。
但我建议在 Api Gateway 和 DynamoDB 之间使用 Lambda,这将有助于分页。
关于amazon-web-services - 使用 AWS API Gateway + DynamoDB 进行分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58173044/