DynamoDB流-将数据写回到表中 [英] DynamoDB streams - write data back into table

查看:369
本文介绍了DynamoDB流-将数据写回到表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下架构:

write -> DynamoDB table -> stream -> Lambda -> write metadata item to same table 

它可以用于许多很多令人讨厌的情况,例如表和项级别的聚合.我已经看到官方AWS工程师在几次技术演讲中推广了这种架构.

It could be used for many, many awsome situations, e.g table and item level aggregations. I've seen this architecture promoted in several tech talks by official AWS engineers.

但是编写元数据项不会添加新项以流式传输并再次运行Lambda吗?

But doesn't writing metadata item add new item to stream and run Lambda again?

如何避免无限循环?有没有一种方法可以避免元数据写入流中?

How to avoid infinite loop? Is there a way to avoid metadata write appearing in stream?

在这种架构下,花费2个流和Lambda请求是不可避免的吗?(我们会根据请求收取费用),即如果它是元数据项,则提前退出Lambda函数.

Or is spending 2 stream and Lambda requests inevitable with this architecture? (we're charged per request) I.e exit Lambda function early if it's metadata item.

推荐答案

由于从DynamoDB流触发AWS Lambda函数是一个二进制选项(开/关),因此不可能仅对某些写入触发AWS Lambda函数到桌子上.因此,将针对刚刚写入DynamoDB表的项目再次调用您的AWS Lambda函数.重要的一点是在您的AWS Lambda函数中具有适当的逻辑,以检测到它已写入该数据,并且在这种情况下不再写入数据.否则,您将得到提到的无限循环,这将是非常不幸的情况,尤其是如果它不被注意的话.

As triggering an AWS Lambda function from a DynamoDB stream is a binary option (on/off), it's not possible to only trigger the AWS Lambda function for certain writes to the table. So your AWS Lambda function will be called again for the items it just wrote to the DynamoDB table. The important bit is to have logic in place in your AWS Lambda function to detect that it wrote that data and to not write data in that case again. Otherwise you'd get the mentioned infinite loop, which would be a really unfortunate situation, especially if it would went unnoticed.

这篇关于DynamoDB流-将数据写回到表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆