I just created demo app (with VPC 'cause I want to use it with RDS and ElasticCache) that has one controller which returns html file. When I tried to test my lambda I got scary 65 seconds response. I created an another lambda from scratch and it starts less than second. As I found so slow start is caused by “Jets.once” command in compiled lambda, but I don’t understand why.
Appreciate your help (
Added VPC endpoint to one of subnets (NAT didn’t help, maybe, I did it wrong) and it resolved problem. I don’t know much about VPC so if someone understand how it works, please, let me know😉
Interesting, previously VPC-enabled lambda functions had a large cold start penalty that you’re describing. AWS Lambda released performance improvements by moving the network creation to build time instead of invocation time in Sep 2019. For details, see their blog post
Believe it’s not perfect and sometimes you may still see a cold start penalty, at least when I tested it at the time. But what you’re describing is much worse at 65 seconds. Unsure. If you’re still interested in the cause, maybe AWS support might be able to provide some clues.
It looks like you found a workaround already though with VPC endpoints. That’s actually quite interesting that a VPC endpoint removes the 65 seconds. Guessing AWS Lambda routes through the VPC endpoint and does not make use of the VPC settings. That’s a good trick and thanks for noting it here for others.