只有在s3中上传了多个文件之后,才可以触发lambda的方法吗 [英] Is there a way to trigger lambda only after multiple files have uploaded in s3

查看:84
本文介绍了只有在s3中上传了多个文件之后,才可以触发lambda的方法吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个用户将多个文件上传到我的S3存储桶中,并以当天作为所有文件的前缀.仅在收到前缀下的所有文件后,才需要触发lambda函数.我该怎么办?.

A user uploads multiple files into my S3 bucket with the current day as prefix for all the files. I need to trigger a lambda function only after I have received all the files under the prefix. How can I do that?.

推荐答案

创建DynamoDb表以跟踪上载的部分.您应该使用HASH键存储文件的前缀或类似的东西.另一个属性可能是零件数.

Create a DynamoDb table to keep track of the uploaded parts. You should use a HASH key to store the prefix of the files, or something like that. Another attribute could be a count of parts.

在上载的每个部分上,将调用一个lambda并将以这种方式更新表上的记录:

On each part uploaded, a lambda will be called and it will update the record at the table in this way:

  1. 读取记录.

  1. Read the record.

如果该记录不存在,则使用条件表达式仅在该记录仍然不存在时使用count = 1创建它.这是为了避免一个lambda覆盖另一个lambda.

If the record does not exist, create it, with count = 1, using a conditional expression to create only if the record still not exists. This is to avoid one lambda overriding another.

  • 如果出现错误,请返回1.

如果记录存在,请使用条件表达式对它进行递增计数以仅在计数等于从1读取的计数时进行更新.

If the record exists, update it incrementing the count with the conditional expression to update only if the count is equal the count read on 1.

  • 如果出现错误,请返回1.

达到预期计数时,请调用lambda对其进行处理.

When you reach the expected count, invoke the lambda to process it.

这篇关于只有在s3中上传了多个文件之后,才可以触发lambda的方法吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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