aws lambda函数为单个事件触发多次 [英] aws lambda function triggering multiple times for a single event

查看:300
本文介绍了aws lambda函数为单个事件触发多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用aws lambda函数将存储桶中上传的wav文件转换为mp3格式,然后将文件移动到另一个存储桶中.它工作正常.但是触发存在问题.当我上传小的wav文件时,lambda函数被调用一次.但是当我上传一个大尺寸的wav文件时,此功能会被多次触发.

I am using aws lambda function to convert uploaded wav file in a bucket to mp3 format and later move file to another bucket. It is working correctly. But there's a problem with triggering. When i upload small wav files,lambda function is called once. But when i upload a large sized wav file, this function is triggered multiple times.

我已经对此问题进行了搜索,发现它是无状态的,因此将被多次调用(不确定此触发器是用于多次上传还是同一次上传).

I have googled this issue and found that it is stateless, so it will be called multiple times(not sure this trigger is for multiple upload or a same upload).

https://aws.amazon.com/lambda/faqs/

是否有任何方法可以一次上传一次调用此功能?

推荐答案

简短版本: 尝试在lambda函数配置中增加超时设置.

Short version: Try increasing timeout setting in your lambda function configuration.

长版:

我想您正在这里遇到lambda函数超时.

I guess you are running into the lambda function being timed out here.

S3事件本质上是异步的,在拒绝该事件之前,至少重试了3次监听S3事件的lambda函数.您提到过,lambda函数在较小的上载过程中仅执行一次(没有错误),并在此基础上进行转换和重新上载.从代码进行转换和重新上传所需的时间可能大于lambda函数的超时设置.

S3 events are asynchronous in nature and lambda function listening to S3 events is retried atleast 3 times before that event is rejected. You mentioned your lambda function is executed only once (with no error) during smaller sized upload upon which you do conversion and re-upload. There is a possibility that the time required for conversion and re-upload from your code is greater than the timeout setting of your lambda function.

因此,您可能要尝试在lambda函数配置中尝试增加超时设置.

Therefore, you might want to try increasing the timeout setting in your lambda function configuration.

顺便说一句,确认您的lambda函数被多次调用的一种方法是查看cloudwatch日志中的事件ID( 67fe6073-e19c-11e5-1111-6bqw43hkbea3 )-/p>

By the way, one way to confirm that your lambda function is invoked multiple times is to look into cloudwatch logs for the event id (67fe6073-e19c-11e5-1111-6bqw43hkbea3) occurrence -

START RequestId: 67jh48x4-abcd-11e5-1111-6bqw43hkbea3 Version: $LATEST

此事件ID代表针对其调用了lambda的特定事件,并且对于负责同一S3事件的所有lambda执行而言,该事件ID应该相同.

This event id represents a specific event for which lambda was invoked and should be same for all lambda executions that are responsible for the same S3 event.

此外,您还可以在以下标记一行lambda执行结束的日志行中查找执行时间(持续时间)-

Also, you can look for execution time (Duration) in the following log line that marks end of one lambda execution -

REPORT RequestId: 67jh48x4-abcd-11e5-1111-6bqw43hkbea3  Duration: 244.10 ms Billed Duration: 300 ms Memory Size: 128 MB Max Memory Used: 20 MB

如果不是解决方案,它至少会为您提供一些在正确方向上进行调试的空间.让我知道怎么回事.

If not a solution, it will at least give you some room to debug in right direction. Let me know how it goes.

这篇关于aws lambda函数为单个事件触发多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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