Do Customer-managed runtimes make cold starts faster? A comparison with packaging large libraries into a ZIP

Do Customer-managed runtimes make cold starts faster? A comparison with packaging large libraries into a ZIP

I compared cold starts for a large library placed in CMR versus bundled entirely in a ZIP on an AWS-managed runtime. CMR had better mean and median results, seemingly lazy-loading chunks like container-image Lambda.
2026.11.26

This page has been translated by machine translation. View original

I'm Iwata from the Retail App Co-creation Department @ Osaka.

Recently, an interesting feature called Customer-managed runtimes was added to Lambda.
By using this feature to install the libraries you want to use on the runtime side in advance, you can use them without including the libraries in the package of each individual Lambda Function.

A question came to mind here: which is more advantageous for cold starts, including libraries in the ZIP package or installing libraries on the runtime side?
Let's verify it right away.

First, a review of cold starts

Let's first review cold starts. As shown in the diagram below, when a cold start occurs, the source code is downloaded. For this reason, it is recommended to minimize the size of the source code in order to keep cold start latency to a minimum.

Cold start steps

※The image is quoted from the official documentation Understanding the Lambda execution environment lifecycle - AWS Lambda

So far this applies to Lambda Functions in general, but in practice there are a few more distinctions.
First, there are two package types for Lambda Functions: ZIP format and container image format. The ZIP format has existed since the Lambda service was launched, while the container image format is a newer format announced at re:Invent 2020. Lambda Functions in container image format incorporate various techniques to speed up cold starts, such as leveraging caches and on-demand chunk loading. For details, please refer to the following blogs.

https://dev.classmethod.jp/articles/devio-osaka-2024-lambda-coldstart/

https://dev.classmethod.jp/articles/reinvent2020-svs404/

The newly introduced Customer-managed runtimes use an architecture in which you push a container image to ECR to create your own runtime, so I suspect the behavior at cold start will be close to that of container image format Lambda. As for ZIP format packages, as far as I know, information on how the internal architecture changed after the container image format appeared (or whether it did not change) has not been covered in detail even in re:Invent sessions.

So, while using a ZIP format package, I checked how cold start performance changes between using an AWS-managed runtime and using Customer-managed runtimes.

Let's try it

Let's get started. We will trigger cold starts with both the AWS-managed runtime and Customer-managed runtimes, then analyze and compare the results using TransactionSearch.

First, measuring with the AWS-managed runtime

First, let's measure the pattern that uses the AWS-managed runtime. ZIP format packages have a limit of up to 250M after extraction, so I prepared a ZIP package stuffed with libraries so that it comes to about 250M.

This time I packed in botocore, numpy, pandas, and scipy. The pyproject.yaml looks like this.

pyproject.toml
[project]
name = "lambda-cmr-coldstart"
version = "0.1.0"
requires-python = ">=3.14"
dependencies = [
    "botocore>=1.44.9",
    "numpy>=2.5.5",
    "pandas>=3.1.1",
    "scipy>=1.18.1",
]

I generated requirements.txt with uv export -o requirements.txt. The contents are as follows.

Contents of requirements.txt
# This file was autogenerated by uv via the following command:
#    uv export -o requirements.txt
botocore==1.44.9 \
    --hash=sha256:1f783e0b31f0053f41f4239b7a7e2e73957f25cdc6b2f45d113f1b575a4db10b \
    --hash=sha256:6966752d38514a8e457ea062ea171b2b320c55bad23c8ae4f74f88296e00890d
    # via lambda-cmr-coldstart
jmespath==1.1.0 \
    --hash=sha256:472c87d80f36026ae83c6ddd0f1d05d4e510134ed462851fd5f754c8c3cbb88d \
    --hash=sha256:a5663118de4908c91729bea0acadca56526eb2698e83de10cd116ae0f4e97c64
    # via botocore
numpy==2.5.5 \
    --hash=sha256:08f1b9abf1707fa89c125aaa17e78389c063fb20ce37a141b47821e996f4a1db \
    --hash=sha256:095113ee2ceab6a9501b184eff5ea806973d3a63d74a8cbc15e4911e754da9c1 \
    --hash=sha256:178cb1eaed819b2cb4e398c554b0776d1499f307e30cb58b9bae1921de35dae6 \
    --hash=sha256:1c24be6a82f5f257afc4dbefde4c3b56dee02146dfed2be2811940e79576b237 \
    --hash=sha256:20145b11776d2f7570cd61351b156a51d3a341822282095baa819d87272bc710 \
    --hash=sha256:229743571f901a082f031f511dc4f926b4b4a714075d98b1ff2af62d836365ac \
    --hash=sha256:2a9c502cdb9a3050ac1686774624cc278658b11f72e11b971a3a8542d6ded357 \
    --hash=sha256:2abd39cfbb3d2af11e9bc8cc92b08cd089b0975fe9b1a30c8b7c740c67d397ce \
    --hash=sha256:2efb2ae4e0414b6bd636dde7235c158cd65dd52891ff64a320a4847a8ce7400f \
    --hash=sha256:31e5be6cd4b896004cb9e416741612ade530fc9a04bceca5219cf66a675113b4 \
    --hash=sha256:32dce94d74bb4d5bb058d65b0d9dad7fa61d07ff9375fd7695d8aa7ea82ee73d \
    --hash=sha256:3d59ab8f6bfc4ffd29b0f558450e17922c1bc88459882e37726fbcd5834afbfd \
    --hash=sha256:410eab02c6718cb42d06ccbb8604659f3522d2ce06ae70cacd5042092659f5af \
    --hash=sha256:479e43c183049ec1a820eeb36549e493924f56b3e893a1d5865d0fff12abad47 \
    --hash=sha256:567994389edd2963b643d63d826138402a63401176f1daf84dbb3204eb838b39 \
    --hash=sha256:5cddc243c75114ba845f01b1f87aca1572dbf7b6c2d88636ed3e1d2bccd7f1bf \
    --hash=sha256:5e202d5facc9c0681834018062466d0b3eabd48c540c3570f72905c97f641a90 \
    --hash=sha256:7ca51125c76817de53473dae31ddc17213776472761bea9cca68a1a0037a4827 \
    --hash=sha256:84dfb1611993a3525b250c955b1e2ebab6ce0ed36e4ab4dd5746432dd362fb5d \
    --hash=sha256:9c3e1ac3cd5d3329f4d38709ff4c21f0621bbe8779c094d6de8ec8347246fcdc \
    --hash=sha256:9f44875964889bd9088cf838d191b58c04088d10b4dc9b140e9da2431ecfbb60 \
    --hash=sha256:a207eb88a18e30add597c366c1db7e79f48fc94084b8e7dbd0eefb95a645db12 \
    --hash=sha256:ab3ff087826c49d07953d0219eb00663ce5b1a0ef0a6b757e1ac041b09387428 \
    --hash=sha256:ad0c8b963f9281f2eb118e283eb61964c716c8e344ed8e8c309b49c586d41ed1 \
    --hash=sha256:ae9cfe4e985139c5f2db69d4310de7348bd0abc02cfdc06991c4419065f6fdca \
    --hash=sha256:b3d328eebe0056c634878c251131d73d74e0c4af317a3aea718816d6fa0bb963 \
    --hash=sha256:b5d08742de581c9eb61102768ccca125a2982913de399611b56981a07278de74 \
    --hash=sha256:b6e30929e3443f46aa7be2749fb003fefbbad6b6a1e2168bf8850a55b657914a \
    --hash=sha256:b6ecbc1ff292c6799067d8064a4dd35cd25ba9d1a24aa41dd635d701691a49b5 \
    --hash=sha256:b7dd0287b6cdd35a27d5678a56b1bc508ff206c2b78b30b4821dd5c3197b393a \
    --hash=sha256:bea7de36bb304a850710c1dfbb35e7cdb9a005928106a3adfc6dc3a753469dec \
    --hash=sha256:bf6fa5a4d73b3a9699a57b8824d4863acde7241808a5305882222843537f02a2 \
    --hash=sha256:c48960d420e90cf305cb1fde0d4e6082cc90512cda87a9acf0b6e04e91cf4abe \
    --hash=sha256:cc6eb7502facce90349b4097a26821af224aaa0ab36e78304711cdb544352882 \
    --hash=sha256:d0c7c0dfabdcb7cde080b7c9ef301c7533e90110198b39965141a903c7dddcf8 \
    --hash=sha256:d64daa409e9b1ac818b0c59e47b005f802e130c8281e40c6a2f7e70c43f75e0f \
    --hash=sha256:d7d9be35d50366fe5ac28188364154c9e1e22ad1b977a06c9465c0680c8eeefe \
    --hash=sha256:dec156cda7322bcb1479ca992794705fe226a911b0ffebe13bff97fa1f3be63c \
    --hash=sha256:e10e81d1db6c8fa507f61bebfd1ea383971dbc40c2005ed4db88fac5538b1ef6 \
    --hash=sha256:e99bf8a3d54693f2063fa6c7d13955d460a9f543d9dbc80e69a92da288259b28 \
    --hash=sha256:ef2a874cc70e2132c1c499268bdc34e211a715e481bc33c97b8a0190f2559295 \
    --hash=sha256:f82a7567c590ff266f8c18fd527a0662edde074de11be256541a656e274f2b05 \
    --hash=sha256:fd47c92e0d1e53f9498b1a30305072434fbae6b5a305cbcab514f959e9ce0fab \
    --hash=sha256:ff5c1ab54a637c0adcdbb69ad10e5c4f1c4dedba69c0d1de383249b70c36908f
    # via
    #   lambda-cmr-coldstart
    #   pandas
    #   scipy
pandas==3.1.1 \
    --hash=sha256:05fed3e3b7c99b226f160e29d7d6cb7ef39638c758cbfe42b3f24ba34f04b859 \
    --hash=sha256:07998b563a4e1ff2d6062ead5a7b145bb7f70096bbd428b7dc556672970ff0ed \
    --hash=sha256:1983c990935a389b0d0d84f278a60ddfe5fcc5a9dc8a10e11a1e26b5d1220552 \
    --hash=sha256:198a8ee3276344a99bb2b05e0a92380b1d5f51469a193b8dcac7cfd1b34af23e \
    --hash=sha256:1e13eb2650f438ee4acda9c50ab7692ea2bc2c5fd5959d1284c83bc7eb287e5e \
    --hash=sha256:211aabaf3f6aec76d87c69522a3e7b26f9e33cb9dc2336359a92b209de582899 \
    --hash=sha256:2b6f34c1fd341128317fd880aee0365020fd14be573c375fb4c72e63567c6ba4 \
    --hash=sha256:326459d8a9be11b5f48c7fc1d63e38ba7cfeaebe5d41bd19e4c5f4f11dc9ac91 \
    --hash=sha256:34e62b61a1e16e125239300f3503f54c4419eabe7df8a364f88cbda2ee289201 \
    --hash=sha256:408067fdb3fcc794836bbcb320d4f15d546f39638156e00b5a2dd6616ee0f388 \
    --hash=sha256:42160e7f78b8a74df8c00e4f3a6010a47bba567fc514dc5029b5a722c2f37ef5 \
    --hash=sha256:42283f38afc154980f7a9c7964161ecc94de8c1bdebaf42528a18d40b556debd \
    --hash=sha256:4e6f9a3036fc6a40c5ba00efe4092a45844212bdb6a63eda4ad5a5a4c8da45eb \
    --hash=sha256:55eb3ed76e7f707786468c1cbf7bdf26f4cbed077487f09f0af474a302b9b079 \
    --hash=sha256:560614c776ea303182708c5ad6ad7e5350645b90ca96f9b955773453622885e0 \
    --hash=sha256:77c2f479cfd0bc76a6c2aeee74d5d8814864ebbee9d351dc5e3a1864e95edbc0 \
    --hash=sha256:78978d0bf2fdb23f2eab1791abd685f03eb580f9247ab1583be8b74e4e270dbb \
    --hash=sha256:8603f29efe58c21729e57d2feb3e86f4c19378242e1e2aeece5f8c3807c421c6 \
    --hash=sha256:862f6fbef3f05005d78df13ffd9c44606fdcb76af8748ab14c901f6181bf3789 \
    --hash=sha256:8e95649e97b925ac63204075233e395250d38ea4051d0540f32df9e08e557654 \
    --hash=sha256:9c6737e125607799df55584c682ff05db4ae4db09180e300448781b7e4448bca \
    --hash=sha256:9c69786754f997cb401b98328678cfd9c7ac64bd111a27e305b44624fcaad5c2 \
    --hash=sha256:a5f29016e40682637b16acb96bd3327120c05d673c4f2d1961481728e6b0a4c4 \
    --hash=sha256:b71ab4607da4c1665f3db3bba62dfe7222f66a0ca353de0e2d9d934480dc19bf \
    --hash=sha256:b80ff163f9d8af866c102976ef727e10a93b1ff04134eb356d3547bd42392857 \
    --hash=sha256:b826e9052502570cd4449aeb0209bcc01e4c25baf774678ddeca225a92302359 \
    --hash=sha256:bf0cf825769b60f9a01a8ff77ed82cfca9ccf2609170814f8f00810f5eaeae71 \
    --hash=sha256:cbe426189f238bee1d05a5ebe11919db8302d397e31d61b10ca0f9a19c75f70e \
    --hash=sha256:daf86c882e376ae2a8a459b2f769258d2b6d75e09f6327440cf6eb8d425c5ceb \
    --hash=sha256:e3b7740decda762970df4b32edae1450630c77c10c5efb4c73a4437727dc7a5c \
    --hash=sha256:f6c63d287fc2eddf698ebd3bd82089aba2dd4f520f6e4f341d28e125644a6137 \
    --hash=sha256:f89fb8e88cc5791995cc076c526eac605adc157b6ac6cc619a33ddd0b8bf5871 \
    --hash=sha256:fdd87cf4d59a3c45f17af6ec965d0bd10b9f15e1b5082d2da11a577439551bcd
    # via lambda-cmr-coldstart
python-dateutil==2.9.0.post0 \
    --hash=sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3 \
    --hash=sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427
    # via
    #   botocore
    #   pandas
scipy==1.18.1 \
    --hash=sha256:011413b7426b75012840e35649e00fe0a2c3bae89fed433876e3a99251572efc \
    --hash=sha256:0ac49ea97594532dd44b7136094d35f5440fa06e6d9c6384a74c01764df388c5 \
    --hash=sha256:0e82073ecc7acc6436fac4b31674109c7e1d3e596789767eda01258a8c9e8123 \
    --hash=sha256:0fcb3c93519f27bb4f0c4b0f7802cdcaca7fcf93267b75edda2e9f4e8a55cbd7 \
    --hash=sha256:10ac20c69d880f77f375db44c22e3e6a644f9fefa291d4cd2fb9790a89fc99fd \
    --hash=sha256:11c423f1049c5755ad4409af52a9ada1cff96fe9b50795d4af3619f292901239 \
    --hash=sha256:179ce34a8d0fe273d8883ba59e17e052247d08973dfcb743ca52bb1cce2d60b0 \
    --hash=sha256:1bca3b943fc2567ea49cd02c99abde49da4d5178ec46f624bd8255cda8755beb \
    --hash=sha256:1d73131e358976663dd969e1fb4ed1404b815cd977eaaedc3b3a133ba2d81c35 \
    --hash=sha256:2a0b02f9fc46f8520330c23d45e6560db7e3a0d927232139427637f98943e11d \
    --hash=sha256:2d3ab0e8c69a17dd3559eab8cbb88f258e285c94d572c2719033f90f83290c89 \
    --hash=sha256:30f464bee641fa8e282577c7dce027308403213c6ca8270bba73285c91024bc5 \
    --hash=sha256:33a834464fdabc0f26a45508df31b3cc5d028e04dbf6c5ed398541418e0a12fe \
    --hash=sha256:49023963c193dacee096301452f223ee24d86ec5807f8df93c0f7221d119e305 \
    --hash=sha256:52c4b7422442aba924d03ad4019852b08a92e64ea187b933135687bfe2747307 \
    --hash=sha256:5632e3ae3d09197c446310cd5187de63e28448ce22f0f67b2b93d97503c0c230 \
    --hash=sha256:78a0d7c918e74a232394117160e7e3db503377572a45bcef8826e4ab8a35feba \
    --hash=sha256:7f4b8bc363b6d65ee2152bec57568e3c52639bb34c46057b09857a307ed5e21d \
    --hash=sha256:82f201b4c878551d48558337aab270d3c6cca5507b8737c8d8a608d234cccde0 \
    --hash=sha256:83de5453a7799afc9048b4616bd085cef126e36412f0ea2f6370c36a2a3a51e7 \
    --hash=sha256:88f0e784020649f88ea48c9f5ddfa403bf9205820667c0914740b392035afb82 \
    --hash=sha256:8bcf3c1ba5d6456e2effd30fcbd3459b044d683fcdac79a2e6830f0bdf7de487 \
    --hash=sha256:911de823097db8b63f034299d12662db93344e6ffa0b881cbb57748974b70168 \
    --hash=sha256:92c14f5bdbfb6216315ce33e78080474082de8b3830122ba97809bfbe65f75c0 \
    --hash=sha256:95298364e251be3e60249facbeeca03631d3bb7584f85879516ec55ac717b81f \
    --hash=sha256:9554bcc6d715ee87a633a3cc8e7703c6628b100dd29cb8a2efc4c0533c7ff729 \
    --hash=sha256:9f2897bf7737392ad0d5213ea7b6add72a4edf5679b3153106aeb88b6507b3b9 \
    --hash=sha256:a1d33a7836f7ddc1993427966a0823468ec41bcbdb1a9f9942d1d7e57f803ba3 \
    --hash=sha256:ac0333bdf38309aa3dcbe7e3fa7ea29e7a2c37c6ea306a757b700ded8e4596ad \
    --hash=sha256:bff0b729edd992766136b34e39cc76bc2fad905aa58897ee72a9cd000a6d8443 \
    --hash=sha256:c24acac1e18912761c4700239bbc1fd32f615af690f1584d49b35859be51324d \
    --hash=sha256:c9d18a33309122074ea483dd92dd444189166b8b2ec429fe9ed5ac73c7a0aa23 \
    --hash=sha256:cbf38d043c1aa4ab306e1ada6ab6eddacc3322a20b7af1b30bc93254b366fe09 \
    --hash=sha256:ceb30a00ce7c92d459819443d29ca486d882b83fb6738bdcbb2a1cce94ac5daa \
    --hash=sha256:cfbf154f2ba187f2ed6cce2639efff7d105f1140573642c0161615b6d91d6a87 \
    --hash=sha256:d84a09d0dad90ba6525d8ac1c2334b33e64bf3ccfe9e841f02feb867a22681e4 \
    --hash=sha256:ddef79fb382df40104a19bb7151b3b23e57c1778fcf857c71ceecd9bd264513f \
    --hash=sha256:e402cf31eb68f453dbb2d36fc6d722b33f24a55d68b2ae1d92fa6305ca71c298 \
    --hash=sha256:eb0dfcf4e28a99c12c999744a2ff67c9b06200e20401c7c88186e33552a46331 \
    --hash=sha256:eda632a7981f69730d6281f451db9c1c370993a2c0d7ddb43e2a809a2862b83a \
    --hash=sha256:f29633129f9fa7e88a3f0fca835de2d030bfc9643f7799e1a0c46cee24d38fc7
    # via lambda-cmr-coldstart
six==1.17.0 \
    --hash=sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274 \
    --hash=sha256:ff70335d468e7eb6ec65b95b99d3a2836546063f63acc5171de367e834932a81
    # via python-dateutil
tzdata==2026.6 ; sys_platform == 'emscripten' or sys_platform == 'win32' \
    --hash=sha256:0a10eec6e13ef16b627fabed9a5f2ba61a62b1c67f327305f4e7e412a70b4aec \
    --hash=sha256:85d2cd9c09f81f0bb29db27759fc83af4f1e620efb814f8c5bf8b4cc4feece6d
    # via pandas
urllib3==2.8.0 \
    --hash=sha256:0cf3cae568d36aa9576b28dfb35f11328f1cb974ca7647d9475ebb86c75ac6e3 \
    --hash=sha256:63bf2ead4c879426ebf22ef2a781eeb4aa3b4ae798a0435506f8687fd5bb9b63
    # via botocore

The deployment package is created and deployed with the SAM CLI. Here is the SAM template.

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Globals:
  Function:
    Timeout: 30
    Tracing: Active
    LoggingConfig:
      LogFormat: JSON
  Api:
    TracingEnabled: true
Resources:
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: dev
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello_world/
      Handler: app.lambda_handler
      Runtime: python3.15
      Architectures:
      - arm64
      Events:
          ApiEvent:
            Type: Api
            Properties:
              Path: /
              Method: get
              RestApiId:
                Ref: ApiGatewayApi

The Lambda Function code is below.

hello_world/app.py
import json
import time

import botocore
import numpy
import pandas
import scipy


def lambda_handler(event, context):
    time.sleep(3)

    return {
        "statusCode": 200,
        "body": json.dumps({
            "message": "hello world",
        }),
    }

It is a simple process that just imports the various libraries in the Init phase. In the handler phase, I added a 3-second sleep so that concurrency goes up and cold starts occur more easily. I build this code with sam build --use-container.

After the build, I checked the size under .aws-sam/build/ and it was 246M. Isn't that a nice size, close to the 250M limit?

$ du -h -d 0 .aws-sam/build/HelloWorldFunction
246M	.aws-sam/build/HelloWorldFunction

Now that it's ready, I deploy with sam deploy.

Once the deployment completes, the Lambda Function can be invoked via API GW, so I'll trigger cold starts using the ab command.

ab -c 200 -n 200 https://<API GWのエンドポイント>/dev/cmr

After the run completes, let's analyze the cold start situation.

When you check the X-Ray trace from the management console, it looks roughly like the following. There are no spans corresponding to downloading the source code or starting the runtime, but there are spans corresponding to the Lambda Invoke and Init phases, so by subtracting the start time of the Invoke processing from the start time of the Init phase, you can calculate an approximation of the time required for runtime startup & source code download.

Trace when a cold start occurs

Let's search this using TransactionSearch.

SOURCE "arn:aws:logs:ap-northeast-1:<AWSアカウントID>:log-group:aws/spans" START=2026-11-26T00:20:00.000Z END=2026-11-26T14:59:59.000Z
|join
    type=inner left=exec right=init
    where exec.traceId=init.traceId
    (SOURCE "arn:aws:logs:ap-northeast-1:<AWSアカウントID>:log-group:aws/spans")
|filter exec.name = "<Lambda Functionの名前>/LambdaService"
| filter init.name = "Init/LambdaExecutionEnvironment"
| filter exec._aws.xray.name != "Overhead"
| filter !ispresent(exec.attributes.aws.xray.inprogress)
| fields formatDate(fromMillis(exec.startTimeUnixNano / 1000000), "%Y-%m-%d %H:%M:%S.%f", "Asia/Tokyo") as execStartTime 
| fields formatDate(fromMillis(exec.endTimeUnixNano / 1000000), "%Y-%m-%d %H:%M:%S.%f", "Asia/Tokyo") as execEndTime 
| fields formatDate(fromMillis(init.startTimeUnixNano / 1000000), "%Y-%m-%d %H:%M:%S.%f", "Asia/Tokyo") as initStartTime 
| fields formatDate(fromMillis(init.endTimeUnixNano / 1000000), "%Y-%m-%d %H:%M:%S.%f", "Asia/Tokyo") as initEndTime 
| fields (init.startTimeUnixNano - exec.startTimeUnixNano) / 1000000 as startupDuration
| display exec.traceId, exec.spanId, exec.name, execStartTime, execEndTime, init.spanId,init.name,initStartTime,initEndTime,startupDuration
| sort execStartTime,exec.traceId

Running this query extracts results like the following.

Query execution result with TransactionSearch

startupDuration is the approximation of the time required for runtime startup & source code download. Aggregating these results gave the following.

Cold start count Min Max Mean Median 95th percentile 99th percentile
108 110.25ms 1213.1479ms 539.009813ms 525.1635ms 701.62447ms 893.149947ms

On average, runtime startup & source code download is completed in about 540ms.

Measuring with Customer-managed runtimes

Next, let's measure the pattern that uses Customer-managed runtimes. First is creating the Customer-managed runtime. Using the following Dockerfile, I install the libraries from the requirements.txt used earlier and build a container image.

FROM public.ecr.aws/sam/build-python3.15:latest-arm64 AS builder
WORKDIR /tmp/work
COPY hello_world/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt --target /tmp/build

FROM public.ecr.aws/lambda/python:3.15.2026.11.20.00-arm64
COPY --from=builder /tmp/build /var/lang/lib/python3.15/site-packages/

Let's check the contents of the built container image. First, enter the container.

docker run -it --rm --entrypoint bash <イメージ名>

Let's check the size of the installed libraries.

bash-5.2# du -h -d 0 /var/lang/lib/python3.15/site-packages/
354M	/var/lang/lib/python3.15/site-packages/

It was 354M. That is about 100M larger than the earlier ZIP package. Just to be sure, let me check the details.

Details of the contents of /var/lang/lib/python3.15/site-packages/ in the container image
bash-5.2# du -h -d 1 /var/lang/lib/python3.15/site-packages/
1.6M	/var/lang/lib/python3.15/site-packages/boto3
32K	/var/lang/lib/python3.15/site-packages/jmespath-1.1.0.dist-info
312K	/var/lang/lib/python3.15/site-packages/pip-26.2.2.dist-info
14M	/var/lang/lib/python3.15/site-packages/pip
40K	/var/lang/lib/python3.15/site-packages/urllib3-2.8.0.dist-info
184K	/var/lang/lib/python3.15/site-packages/jmespath
48K	/var/lang/lib/python3.15/site-packages/awslambdaric-4.2.3.dist-info
268K	/var/lang/lib/python3.15/site-packages/botocore-1.43.127.dist-info
184K	/var/lang/lib/python3.15/site-packages/awslambdaric
44K	/var/lang/lib/python3.15/site-packages/simplejson-4.3.0.dist-info
40K	/var/lang/lib/python3.15/site-packages/python_dateutil-2.9.0.post0.dist-info
48K	/var/lang/lib/python3.15/site-packages/boto3-1.43.127.dist-info
40K	/var/lang/lib/python3.15/site-packages/s3transfer-0.19.3.dist-info
1.2M	/var/lang/lib/python3.15/site-packages/urllib3
56K	/var/lang/lib/python3.15/site-packages/__pycache__
24K	/var/lang/lib/python3.15/site-packages/snapshot_restore_py-1.0.0.dist-info
864K	/var/lang/lib/python3.15/site-packages/dateutil
736K	/var/lang/lib/python3.15/site-packages/s3transfer
33M	/var/lang/lib/python3.15/site-packages/botocore
1.4M	/var/lang/lib/python3.15/site-packages/simplejson
28K	/var/lang/lib/python3.15/site-packages/six-1.17.0.dist-info
25M	/var/lang/lib/python3.15/site-packages/numpy.libs
380K	/var/lang/lib/python3.15/site-packages/numpy-2.5.5.dist-info
412K	/var/lang/lib/python3.15/site-packages/pandas-3.1.1.dist-info
31M	/var/lang/lib/python3.15/site-packages/scipy.libs
86M	/var/lang/lib/python3.15/site-packages/pandas
24K	/var/lang/lib/python3.15/site-packages/bin
332K	/var/lang/lib/python3.15/site-packages/scipy-1.18.1.dist-info
276K	/var/lang/lib/python3.15/site-packages/botocore-1.44.9.dist-info
40M	/var/lang/lib/python3.15/site-packages/numpy
118M	/var/lang/lib/python3.15/site-packages/scipy
354M	/var/lang/lib/python3.15/site-packages/

Since boto3 and the RIC are already included, the size inevitably ends up larger than the earlier ZIP package. It seems difficult to match the size exactly, so I'll proceed with the verification as is. I pushed the built image to ECR to create the Customer-managed runtime, then added the following to the SAM template and deployed a second Lambda Function. The source code of the Lambda Function itself is exactly the same as before.

  HelloWorldFunction2:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: hello_world2/
      Handler: app.lambda_handler
      Runtime: custom
      Architectures:
      - arm64
      RuntimeConfig:
        RuntimeArn: <作成したランタイムのARN>
        RuntimeAlias: <作成したランタイムのエイリアス>
      Events:
          ApiEvent:
            Type: Api
            Properties:
              Path: /cmr
              Method: get
              RestApiId:
                Ref: ApiGatewayApi
    Metadata:
      BuildMethod: python3.15

After deploying, I trigger cold starts with the ab command as before and analyze with TransactionSearch. The results were as follows.

Cold start count Min Max Mean Median 95th percentile 99th percentile
105 106.3519ms 10584.373ms 279.0762952ms 185.9648ms 198.50624ms 484.97468ms

Compared with the earlier pattern where all libraries were packed into the ZIP package, the mean and median have improved. On the other hand, the maximum exceeds 10 seconds. I was curious, so I checked the trace that recorded the maximum. The trace in question was as follows.

Trace when the init phase exceeded 10 seconds

You can see that the first Init phase exceeded the 10-second limit and a retry occurred. The second Init phase completed in 4.82 seconds. What do you think? Judging from this behavior, the internal architecture seems to be the same as that of container image format Lambda, and the chunks of the container image appear to be loaded on demand. It would make sense if the chunks containing the libraries had not yet been loaded at the point the runtime started, and the chunk download was executed for the first time when the libraries were imported in the Init phase, making the duration longer.

Also, although the maximum exceeded 10 seconds, in the execution that took the second longest, the time until the Init phase started was 252 milliseconds and the Init phase itself took 703 milliseconds. It makes sense if we assume that it took a long time at the first cold start because the container image did not exist in the cache, while at the second and subsequent cold starts the container image could be loaded from the Dedicated local cache, so only a slight overhead was incurred.

I also suspected that a failure might have happened to occur on the Lambda infrastructure side, and tried recreating the runtime several times and deploying to another region, but the phenomenon of the Init phase exceeding 10 seconds was reproducible, so I conclude it is a phenomenon caused by the internal architecture of Customer-managed runtimes.

As an experiment, I moved the library import processing into the handler, removed the sleep, and deployed to another region to reproduce the delay; the trace results were as follows.

Trace after modifying to import inside the handler

Here is the entire code.

import json

def lambda_handler(event, context):

    import botocore
    import numpy
    import pandas
    import scipy
    
    return {
        "statusCode": 200,
        "body": json.dumps({
            "message": "hello world",
        }),
    }

Until now the imports were done in the Init phase, so boost host CPU was in effect, but this time the imports are in the handler, so there is the difference that only CPU power equivalent to 128M of memory can be used; even so, the import processing seems to have taken roughly 16 seconds. It seems fair to say that when the cache has not been warmed up, loading libraries installed in a Customer-managed runtime incurs a large delay.

Interesting results came out, so I went on a bit of a tangent, but that concludes the measurement results for using a Customer-managed runtime!!

Summary

Here is a summary of the verification results again.

Verification pattern Cold start count Min Max Mean Median 95th percentile 99th percentile
Package all libraries in the ZIP and use the AWS-managed runtime 108 110.25ms 1213.1479ms 539.009813ms 525.1635ms 701.62447ms 893.149947ms
Use a Customer-managed runtime with libraries installed 105 106.3519ms 10584.373ms 279.0762952ms 185.9648ms 198.50624ms 484.97468ms
  • The minimum is about the same
  • The maximum is overwhelmingly larger when using the Customer-managed runtime
  • For the other metrics, using the Customer-managed runtime gives better numbers

Also, regarding the maximum when using the Customer-managed runtime, from the verification results so far I believe the cause was a cache miss in the processing that lazily loads chunks of the container image. The architecture behind Customer-managed runtimes has not been published, but my opinions based on this verification are as follows.

  • Using a Customer-managed runtime with libraries installed often results in smaller cold start latency than using an AWS-managed runtime with libraries packaged in a ZIP
  • However, if the container image of the Customer-managed runtime is not in the cache, the delay in loading chunks becomes large, so conversely using the AWS-managed runtime results in smaller latency
  • Since chunk loading of the container image is lazy, depending on the implementation the processing in the Init phase or Handler phase may be delayed.

※This is only a discussion based on behavior seen from the outside, so I cannot guarantee what the actual behavior is. Please keep that in mind.

re:Invent 2026 is coming up soon, but will there be a session that deep dives into the Lambda infrastructure this year? While hoping for a dense session like SVS404 from re:Invent 2018 and 2019, I intend to enjoy re:Invent (from Japan).

References

Share this article