amazon-web-servicesamazon-s3aws-lambda

aws lambda function triggering multiple times for a single event


I am using the AWS lambda function to convert uploaded WAV files in a bucket to mp3 format and later move the file to another bucket. It is working correctly. But there's a problem with triggering. When I upload small WAV files, the 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 if this trigger is for multiple uploads or the same upload).

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

Is there any method to call this function once for a single upload?


Solution

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

    Long version:

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

    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.

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

    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
    

    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.

    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.