简体   繁体   English

如何触发Lambda只有一次多部分上传S3触发器?

[英]How to trigger Lambda only one time for multipart upload S3 triggers?

I have a AWS Lambda function that: 我有一个AWS Lambda函数:

  1. reacts to an S3 ObjectCreated trigger S3 ObjectCreated触发器做出反应
  2. ssh into an ec2 instance and ssh到ec2实例和
  3. runs a python script 运行python脚本

This python script will then run EMR to process all these S3 part-files that were just created. 然后,此python脚本将运行EMR以处理刚刚创建的所有这些S3部件文件。 (Yes, the files must be processed jointly.) (是的,必须联合处理这些文件。)

However, the part-files ( file_part_0000 , file_part_0001 , file_part_0002 , etc.) are created as multipart uploads. 但是,部分文件( file_part_0000file_part_0001file_part_0002等)将创建为分段上传。

Lambda Event: {..., "eventName": "ObjectCreated:CompleteMultipartUpload", ...}

It's my understanding that this trigger would force Lambda to ssh and run the python script as many time as there are part files. 我的理解是,这个触发器会强制Lambda ssh并运行python脚本的次数和部分文件一样多。 I only want Lambda to ssh and run the script once . 我只希望Lambda ssh并运行一次脚本。

Is there any way to have the Lambda be triggered once for each "series" of multipart uploads? 对于每个“系列”的分段上传,有没有办法让Lambda被触发一次

As mentioned in Configuring Amazon S3 Event Notifications 配置Amazon S3事件通知中所述

You will not receive event notifications from failed operations. 您将不会收到失败操作的事件通知。

And there is a reason that the event is call s3:ObjectCreated:CompleteMultipartUpload , the event should trigger only if your multipart are upload completely. 并且有一个原因是事件是调用s3:ObjectCreated:CompleteMultipartUpload ,只有当您的多部分完全上传时才会触发该事件。

On the other hand, perhaps you should make S3 event trigger to send info to SQS. 另一方面,也许你应该让S3事件触发器向SQS发送信息。 So you can make your python program can watching SQS queue and process the file. 因此,您可以使您的python程序可以观看SQS队列并处理该文件。 With SQS, you don't need to make passwordless setup or store private key in lambda to ssh the server. 使用SQS,您无需在lambda中进行无密码设置或存储私钥即可ssh服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM