Will the cold starts of my AWS Lambda function take longer if I use an ECR image/containers?

Viewed 2598

Will the cold starts of my AWS Lambda function take longer if I use a image from ECR instead of a jar from S3 as my source code? I'm thinking that yes, because the image is larger due to the additional OS layer (even though... the regular Lambda should have some OS layer as well), but I couldn't find any performance benchmarks.

Thanks!

4 Answers

Yes, you will have longer cold starts, resulting in much higher response times.

It is really dependent on the image you're downloading from ECR but in general, it will be slower as a Docker container is being used instead of Lambda managing the runtime environment for you (which reduces the time to it takes to start a new execution environment for cold Lambdas).

The main cause is the size of the ECR image, which is also why there is a limit on large Lambda ZIP archives.

You can see here how the size will affect the 2 tasks that run during cold start, defined by AWS as Download your code & Start new execution environment.

cold start duration tasks & invocation duration tasks

I would advise you to definitely use the managed runtime as opposed to containers unless you need to use them as it will automatically result in faster execution.

Yes, packaging a lambda as a container image rather than a zip will lead to longer cold starts.

There are 2 reasons for this:

  1. Container images tend to be larger, thus taking more time to load.
  2. Containers need to initialize the underlying operating system.

In general, use a container over a plain lambda when you benefit from having the underlying OS functionality. Otherwise, stick to zip files.

Related