Skip to content

fix(aws-lambda): Load path-style handlers once per invocation - #8134

Open
pabloDeputter wants to merge 3 commits into
masterfrom
pablo/aws-lambda-load-handler-once
Open

pabloDeputter wants to merge 3 commits into
masterfrom
pablo/aws-lambda-load-handler-once

Conversation

@pabloDeputter

Copy link
Copy Markdown
Member

Description

Path-style handlers, e.g. SENTRY_INITIAL_HANDLER=app/index.handler, were manually loaded and never cached unlike dotted handlers, e.g. index.handler which automatically ended up in sys.modules; so module was loaded again on every warm invocation and state was lost.

Changes & Results

Loader now does the same as Lambda runtime itself: / is turned into . and importlib.import(...) is called; Python caches the module, so it runs exactly once per execution environment.

Some results below on a Lambda function (python3.13, arm64, 512 MB) that creates 3 boto3 clients at import:

warm-duration

Warm invocations: p50 122ms => 58ms; p99 180ms => 69ms.

cold-start

Cold starts remain the same, 1.4s for both.

memory

Peak memory also drops from 117 MB => 108 MB and is fixed on invocations, unlike the old layer which grows over time because each call creates new clients.

Issues

Resolves #8079 & PY-3016

@pabloDeputter
pabloDeputter force-pushed the pablo/aws-lambda-load-handler-once branch from ca3a347 to fac06dc Compare October 27, 2026 13:27
@pabloDeputter
pabloDeputter marked this pull request as ready for review October 27, 2026 13:31
@pabloDeputter
pabloDeputter requested a review from a team as a code owner October 27, 2026 13:31
@github-actions

Copy link
Copy Markdown
Contributor

Coverage Results 📊

✅ 136571 passed | ⏭️ 7334 skipped | Total: 143905 | Pass Rate: 94.9% | Execution Time: 446m 32s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +2199
Passed Tests 📈 +2199
Failed Tests —
Skipped Tests —

All tests are passing successfully.

✅ Patch coverage is 100.00% (no changed executable lines found; target 80%).
Project statement coverage is 90.30% (up 0.03 percentage points from base (9397950) to head (fac06dc)).

Coverage diff
@@            Coverage Diff             @@
##        master     #8134       +/-##
==========================================
+ Coverage    90.27%    90.30%    +0.03%
==========================================
  Files          203       203         —
  Tracked lines     26880     26880         —
  Branches     10042     10042         —
==========================================
+ Hits         24266     24273        +7
+ Misses        2614      2607        -7
  Partials      1520      1520         —

Generated by Coverage Action

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(aws-lambda): Load handler module only once in the layer

1 participant