AWS Lambda 是否严格按顺序处理 DynamoDB 流事件?

Does AWS Lambda process DynamoDB stream events strictly in order?

我正在编写一个处理来自 DynamoDB 流的项目的 Lambda 函数。

我认为 Lambda 背后的部分要点是,如果我有大量事件,它会启动足够多的实例以同时处理它们,而不是通过单个实例按顺序提供它们。只要两个事件有不同的密钥,我就可以接受它们被乱序处理。

但是,我刚刚在 Understanding Retry Behavior 上阅读了这个页面,上面写着:

For stream-based event sources (Amazon Kinesis Data Streams and DynamoDB streams), AWS Lambda polls your stream and invokes your Lambda function. Therefore, if a Lambda function fails, AWS Lambda attempts to process the erring batch of records until the time the data expires, which can be up to seven days for Amazon Kinesis Data Streams. The exception is treated as blocking, and AWS Lambda will not read any new records from the stream until the failed batch of records either expires or processed successfully. This ensures that AWS Lambda processes the stream events in order.

"AWS Lambda processes the stream events in order"是否意味着 Lambda 不能同时处理多个事件?有没有办法让它同时处理来自不同键的事件?

流记录被组织成组或碎片。

根据 Lambda documentation,并发是在分片级别实现的。在每个分片中,流事件按顺序处理。

Stream-based event sources : for Lambda functions that process Kinesis or DynamoDB streams the number of shards is the unit of concurrency. If your stream has 100 active shards, there will be at most 100 Lambda function invocations running concurrently. This is because Lambda processes each shard’s events in sequence.

并且根据Limits in DynamoDB,

Do not allow more than two processes to read from the same DynamoDB Streams shard at the same time. Exceeding this limit can result in request throttling.

AWS Lambda 支持 Parallelization Factor for Kinesis and DynamoDB Event Sources, the order is still guaranteed for each partition key, but not necessarily within each shard when Concurrent batches 每个分片设置为大于 1。因此需要修改已接受的答案。