单个 DynamoDB 流上的多个 AWS Lambda 函数

Multiple AWS Lambda functions on a Single DynamoDB Stream

我有一个 Lambda 函数,多个 DynamoDB 流被配置为事件源,这是更大管道的一部分。在进行检查时,我发现其中一个下游组件中缺少一些数据。我想编写一个更简单的 Lambda 函数,该函数被配置为前面提到的 DynamoDB 流之一的事件源。这会导致我的 DynamoDB 流之一有两个从中读取的 Lambda 函数。我想知道这样可以吗? Lamdba 函数是否保证接收流中的所有记录,是否有任何资源(Read/Write 吞吐量)限制我需要注意。在 AWS 网站上找不到与此相关的任何文档,但我确实找到了有关分片处理的文档

To access a stream and process the stream records within, you must do the following:

  • Determine the unique Amazon Resource Name (ARN) of the stream that you want to access.
  • Determine which shard(s) in the stream contain the stream records that you are interested in.
  • Access the shard(s) and retrieve the stream records that you want.

Note No more than 2 processes at most should be reading from the same Streams shard at the same time. Having more than 2 readers per shard may result in throttling.

不确定上述情况与将流配置为 Lambda 的事件源而不是使用 API 从流中手动读取的情况有何关系。

您可以让多个 Lambda 将同一个流用作事件源。他们不会互相干扰。但正如文档所述:“请注意,最多不应有超过 2 个进程同时从同一个 Streams 分片读取。每个分片有超过 2 个读者可能会导致节流。” 因此,如果您大量使用流,则连接到它们的 Lambda 不应超过两个。

此 AWS 博客 post https://aws.amazon.com/de/blogs/database/how-to-perform-ordered-data-replication-between-applications-by-using-amazon-dynamodb-streams/ 建议您仅将一个 Lambda 附加到 DDB 流并使用扇出模式进行并行处理。这将帮助您按顺序处理 DDB 项目。