基于项目计数器的 DynamoDB 触发事件
DynamoDB trigger event based on item counter
我们有一个 DynamoDB table,它有一个属性计数器,多个 lambda 将基于一个事件异步递减。我想在计数器变为零时触发另一个事件。我怎样才能做到这一点?我正在使用 DynamoDB 增强客户端 (Java SDK 2)。
我尝试使用 DynamoDBVersionAttribute,但维护它非常棘手,因为计数器正在异步更新。
首先重要的是要了解默认情况下 DynamoDB 使用 eventually consistent read model which will not function well if you're expecting your counter to be atomic.
An atomic counter would not be appropriate where overcounting or undercounting can't be tolerated (for example, in a banking application). In this case, it is safer to use a conditional update instead of an atomic counter.
而是看看 conditional updates。
与其尝试在更新时获取值,不如看看在执行写入后使用 DynamoDB streams 做出反应。
通过以这种方式处理偶数,您可以根据条件触发和处理事件,例如您的情况下计数器达到 0。
流可以被另一个应用程序读取或与其他服务集成,例如 Lambda to process the events。
我们有一个 DynamoDB table,它有一个属性计数器,多个 lambda 将基于一个事件异步递减。我想在计数器变为零时触发另一个事件。我怎样才能做到这一点?我正在使用 DynamoDB 增强客户端 (Java SDK 2)。
我尝试使用 DynamoDBVersionAttribute,但维护它非常棘手,因为计数器正在异步更新。
首先重要的是要了解默认情况下 DynamoDB 使用 eventually consistent read model which will not function well if you're expecting your counter to be atomic.
An atomic counter would not be appropriate where overcounting or undercounting can't be tolerated (for example, in a banking application). In this case, it is safer to use a conditional update instead of an atomic counter.
而是看看 conditional updates。
与其尝试在更新时获取值,不如看看在执行写入后使用 DynamoDB streams 做出反应。
通过以这种方式处理偶数,您可以根据条件触发和处理事件,例如您的情况下计数器达到 0。
流可以被另一个应用程序读取或与其他服务集成,例如 Lambda to process the events。