Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I force a complete cold start of an AWS lambda function on a VPC?

I have a lambda function written in Python that uses a couple of heavyweight dependencies (NumPy, pandas, goodtables, etc.) and is also connected to a VPC (for access to a Postgres RDS instance)

The cold start execution time of this function is huge (16.2 seconds) when it's executed after a while (> 4-6 hours)

However, if I update the function code and invoke it a second time (shortly after the first execution), the cold start execution time reduces drastically (3 seconds)

If I invoke the function again without updating it so it's a warm start, the execution time goes down even further (313 ms)

I suspect the first cold start (16.2 secs) is when Lambda sets up an ENI for access to VPC resources and the ENI is reused during the second cold start (3 secs) so the time taken to re-create the ENI is avoided.

I am trying to optimize the cold start time of this function and want it to start from scratch to see how fast it can execute when starting completely cold (i.e. no ENI + cold start).

Is there a way to do this and do it repeatedly?

like image 356
Vinayak Avatar asked Mar 17 '19 11:03

Vinayak


1 Answers

You can toggle the memory up, save and reset it back again.

You can also add a new environment variable.

This forces all existing warm lambda's to be disposed and a new cold start on the next invocation of the lambda.

like image 107
Damian Haynes Avatar answered Oct 20 '22 10:10

Damian Haynes