4

I have an API function in python and deployed it on aws lambda using zappa. When I am hitting my API after 15 minutes time its taking atleast 5 to 10 seconds to respond (which is too long for my API) for first request. I have came to know about cold start issue in aws lambda. How to keep lambda warm using zappa python?

  • Possible duplicate of [Lambda cold start possible solution?](https://stackoverflow.com/questions/37931010/lambda-cold-start-possible-solution) – bishop Apr 12 '19 at 15:31
  • https://hackernoon.com/im-afraid-you-re-thinking-about-aws-lambda-cold-starts-all-wrong-7d907f278a4f – bishop Apr 12 '19 at 15:31

1 Answers1

3

Zappa has a default warmer that keeps invoking the lambda to avoid cold starts - check https://github.com/Miserlou/Zappa#advanced-usage (make sure keep_warm is set to true).

You can verify that there is a CloudWatch event rule of a scheduled event.

Ronyis
  • 1,803
  • 16
  • 17
  • 1
    Yes, you are right Zappa setting json file has an option keep_warm which is set to true by default. Also I am able to view the view the keep warm triggered every 5minutes in Zappa logs. Is there any additional settings I need to make. Because after adding that settings also my API is taking too long to respond for the first time. – Naveen Apr 13 '19 at 18:20
  • 2
    Make sure to make the initialization needed for your lambda at the import level of the handler, and not when it is first called (for example - connecting to a database, etc.). – Ronyis Apr 14 '19 at 09:16
  • @Naveen, I'm experiencing the same issue, how did you fix it? – bieboebap Feb 08 '23 at 16:41