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

查看:16
本文介绍了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 事件本质上是异步的,侦听 S3 事件的 lambda 函数在该事件被拒绝之前至少重试 3 次.您提到您的 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) 发生 -

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 执行应该相同.

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 执行结束的日志行中查找执行时间 (Duration) -

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天全站免登陆