AWS Lambda function fires twice

I am using the AWS Lambda function (written in python) to send an email whenever an object is loaded into a pre-installed S3 bucket. The object is loaded via the AWS PHP SDK into the S3 bucket and uses multi-page loading. Whenever I check my code (on the Lambda code editor page), it works fine and I only get one email.

But when the object is loaded through the PHP SDK, the Lambda function runs twice and sends two letters, both with different message identifiers. I tried different email addresses, but each address receives exactly two duplicate emails.

Can someone guide me where I can go wrong? I am using the boto3 library, which is imported with python sample code to send email.

+5
source share
2 answers

Yes, we have it, and it is not associated with email, it is associated with S3, which fires several events for a single download. Like many messaging systems, Amazon does not guarantee "one-time delivery" of event notifications from S3, so your Lambda function will have to deal with this itself.

Not the biggest, but doable.

Some form of cache with the details of the previous few requests, so you can see if you have processed any particular event message or not.

+7
source

I also encounter the same problem, in my case, on every PUT event, a lambda should be launched in the S3 bucket, it will run twice with the same aws_request_id and aws_lambda_arn .

To fix this, track aws_request_id (this identifier will be unique for each lambda event) somewhere and check the handler. If the same aws_request_id exists, do nothing, otherwise do as usual.

+1
source

Source: https://habr.com/ru/post/1240597/


All Articles