在AWS Lambda中处理分页的最佳方法是什么?
我有一个简单地由lambda处理的get请求,该请求从DynamoDB表中读取所有行。因此,它返回所有记录。
但是,当我那里有大量记录时,它的时间是因为在这张桌子上进行扫描需要超过29秒。
解决这个问题的最佳方法是什么?如果是这样,最好的方法是什么?
我正在使用Nodejs V3 SDK。
I have a GET request that simply is handled by lambda which reads all the rows from dynamodb table. So it returns all records.
But when I have a very large amount of records there, it times out because doing scan on this table takes more than 29 seconds.
What is the best way to handle this, pagination ? If so, what would be the best way to do it?
Im using nodejs v3 sdk.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于Dynamo DB查询操作将数据返回至1 MB,因此分页逻辑将如下:
一些其他考虑因素-1)增加lambda超时2)也增加了lambda内存。
PS我对节点JS并不熟悉,请原谅我的无知。
Since dynamo db query operation returns data up to 1 mb, the pagination logic would be as follows:
some additional consideration - 1) Increase the lambda timeout 2) increase lambda memory as well.
p.s. I am not familiar much with Node JS, excuse my ignorance.
您可以通过传递
limit
以及表名来设置自己的页面大小。这是一个每页20个结果的示例:然后,您必须从结果有效载荷中传递
lastEvaledekey
才能获取下一页,将其更名为exclusivestartkey
。此示例假设您的密钥是字符串类型:另外,请注意,您可以直接从API网关访问DynamoDB,直接没有中间的lambda。像此帖子。
You can set your own page size by passing
Limit
along with your table name. Here is an example with 20 results per page:Then, you'll have to pass
LastEvaluatedKey
from the resulting payload to get the next page, renamed asExclusiveStartKey
. This example assumes your key is of string type:Also, mind that you can access DynamoDB from API Gateway directly not having a lambda in-between. Like in this post.