Nimrod Geva
Nimrod Geva

Reputation: 45

Lambda times out after ending

After finishing successfully, a Lambda function insists on timing out.

The function's triggering event is s3:ObjectCreated:*.

The function uses MongoDB Atlas and does so according to the optimisation suggestions on https://www.mongodb.com/blog/post/optimizing-aws-lambda-performance-with-mongodb-atlas-and-nodejs, including setting: context.callbackWaitsForEmptyEventLoop = false; before using the DB.

The function also calls some AWS SDK methods with successfully resolved promises.

After finishing my code successfully and doing everything it set out to do, I get the following in my CloudWatch logs, (both the request's END event and its timeout):

START RequestId: XXX    
... my logs...
END RequestId: XXX
REPORT RequestId: XXX   Duration: 6001.12 ms    Billed Duration: 6000 ms Memory Size: 1024 MB   Max Memory Used: 49 MB  
XXX Task timed out after 6.00 seconds

The function then repeats itself twice more with the same unfortunate result.

Any immediate suspects? Where should I look?

Upvotes: 1

Views: 977

Answers (1)

Noel Llevares
Noel Llevares

Reputation: 16077

You need to call callback(null, <any>) in order to end your function handler and tell Lambda that your function executed successfully.

Without that, Lambda will retry the same invocation after a delay and it will again finish but without telling Lambda that it finished successfully.

Upvotes: 1

Related Questions