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:
Read the record.
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.
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.
When you reach the expected count, invoke the lambda to process it.