Is there a way to trigger lambda only after multiple files have uploaded in s3

孤街浪徒 提交于 2020-05-24 07:54:56

问题


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?.


回答1:


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.

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

  1. Read the record.

  2. 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.

    • If error, back to 1.
  3. 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.

    • If error, back to 1.
  4. When you reach the expected count, invoke the lambda to process it.



来源:https://stackoverflow.com/questions/60758077/is-there-a-way-to-trigger-lambda-only-after-multiple-files-have-uploaded-in-s3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!