且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 lambda 函数处理 SQS 队列(不是通过计划事件)?

更新时间:2023-11-25 14:45:58

[这不会直接回答你明确的问题,所以根据我的经验,它会被否决:) 但是,我会回答你试图解决的基本问题解决.]

[This doesn't directly answer your explicit question, so in my experience it will be downvoted :) However, I will answer the fundamental problem you are trying to solve.]

我们处理大量传入请求并将它们提供给 AWS Lambda 函数以便以有节奏的方式写入 DynamoDB 的方式是将建议架构中的 SQS 替换为 Amazon Kinesis 流.

The way we take a flood of incoming requests and feed them to AWS Lambda functions for writing in a paced manner to DynamoDB is to replace SQS in the proposed architecture with Amazon Kinesis streams.

Kinesis 流可以驱动 AWS Lambda 函数.

Kinesis streams can drive AWS Lambda functions.

Kinesis 流保证任何给定键的传递消息的顺序(适用于有序的数据库操作).

Kinesis streams guarantee ordering of the delivered messages for any given key (nice for ordered database operations).

Kinesis 流让您可以指定可以并行运行的 AWS Lambda 函数的数量(每个分区一个),这可以与您的 DynamoDB 写入容量相协调.

Kinesis streams let you specify how many AWS Lambda functions can be run in parallel (one per partition), which can be coordinated with your DynamoDB write capacity.

Kinesis 流可以在一次 AWS Lambda 函数调用中传递多条可用消息,从而实现进一步优化.

Kinesis streams can pass multiple available messages in one AWS Lambda function invocation, allowing for further optimization.

注意:实际上是 AWS Lambda 服务从 Amazon Kinesis 流中读取然后调用函数,而不是 Kinesis 流直接调用 AWS Lambda;但有时更容易想象 Kinesis 驱动它.对用户的结果几乎相同.

Note: It's really the AWS Lambda service that reads from Amazon Kinesis streams then invokes the function, and not Kinesis streams directly invoking AWS Lambda; but sometimes it's easier to visualize as Kinesis driving it. The result to the user is nearly the same.