15

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!

Ermiya Eskandary
  • 15,323
  • 3
  • 31
  • 44
user361676
  • 719
  • 2
  • 7
  • 16

5 Answers5

13

I'm surprised at the conclusion of the other answers here.

IT DEPENDS

Linked earlier, this blog post performs data tests. From that post:

enter image description here enter image description here

If your function is a pure function. It'll perform way better (1st picture) as most have said, but once your function acts more like a Framework the size of the zip grows and all it takes is a few megs and S3 is simply too slow.

To be clear, your container/program needs to have a fast start time, but that's irrespective of the size or lambda.

That second graph is incredible, 5GB container loading in < 2s.

nitsujri
  • 1,448
  • 2
  • 16
  • 29
7

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.

Ermiya Eskandary
  • 15,323
  • 3
  • 31
  • 44
7

"Lambda also optimizes the image and caches it close to where the functions runs so cold start times are the same as for .zip archives" from https://aws.amazon.com/blogs/compute/working-with-lambda-layers-and-extensions-in-container-images/

hb2638
  • 109
  • 2
  • 2
3

Docker images will be definitely slower cold start. This is because of bigger size and additional OS. Lambda loads your code into its managed environment instead loading you whole docker image.

Links for reference: Some graphs comparing docker with native java lambda: https://mikhail.io/serverless/coldstarts/aws/

Additional information about lambda containers: https://chariotsolutions.com/blog/post/getting-started-with-lambda-container-images/

Lucasz
  • 1,150
  • 9
  • 19
0

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.