Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS lambda execution fails only first time I run it with 'customer function error'

I trigger a lambda function via API gateway and everything works perfectly with the one exception that the very first time I trigger it on a given day it fails.

Strangely, the lambda function logs don't show any errors. I get my usual START log statement and then the request and context of the trigger, then after 5s, it ends unexpectedly.

When I look into the API gateway logs this is the error it returns:

Lambda execution failed with status 200 due to customer function error: 2018-12-10T11:00:31.208Z cc233168-fc9n-11fc-a05a-577bb4sd2b2ccc Task timed out after 5.01 seconds.

Has anyone encountered a similar problem? What is customer function error and how may I resolve this?

like image 707
Ludo Avatar asked Nov 19 '25 10:11

Ludo


1 Answers

without knowing much of the background code you are using, i would termed this a Cold Start. Cold start happens for the first request where your function has not be called for a very long time. If you notice error message says "Time Out after 5.01 seconds. which is default set. you can increase a time out.

Alternatively, you could consider reducing the impact of cold starts by reducing the length of cold starts reference :

  1. by authoring your Lambda functions in a language that doesn’t incur a high cold start time — i.e. Node.js, Python, or Go
  2. choose a higher memory setting for functions on the critical path of handling user requests (i.e. anything that the user would have to wait for a response from, including intermediate APIs)
  3. optimizing your function’s dependencies, and package size

You can also explore by putting a cron job through Cloud Watch after every specific interval to call your API through PING

like image 127
Yash Bindlish Avatar answered Nov 21 '25 02:11

Yash Bindlish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!