Skip to content

fix(aws-lambda): Load path-style handlers once instead of on every invocation - #8134

Merged
sentrivana merged 5 commits into
masterfrom
pablo/aws-lambda-load-handler-once
Nov 11, 2026
Merged

sentrivana merged 5 commits into
masterfrom
pablo/aws-lambda-load-handler-once

Conversation

@pabloDeputter

Copy link
Copy Markdown
Contributor

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

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Results 📊

✅ 138998 passed | ⏭️ 7669 skipped | Total: 146667 | Pass Rate: 94.77% | Execution Time: 458m 55s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +1552
Passed Tests 📈 +1554
Failed Tests —
Skipped Tests 📉 -2

All tests are passing successfully.

✅ Patch coverage is 100.00% (no changed executable lines found; target 80%).
Project statement coverage is 90.24% (down 0.01 percentage points from base (63707d7) to head (fb3fbfd)).

Coverage diff
@@            Coverage Diff             @@
##        master     #8134       +/-##
==========================================
- Coverage    90.25%    90.24%    -0.01%
==========================================
  Files          203       203         —
  Tracked lines     27114     27114         —
  Branches     10136     10136         —
==========================================
- Hits         24470     24468        -2
- Misses        2644      2646        +2
- Partials      1538      1540        +2

Generated by Coverage Action

@sentry-junior sentry-junior Bot changed the title fix(aws-lambda): Load path-style handlers once per invocation fix(aws-lambda): Load path-style handlers once instead of on every invocation Nov 11, 2026
@sentrivana
sentrivana enabled auto-merge (squash) November 11, 2026 09:55
@sentrivana
sentrivana merged commit f6d6ce9 into master Nov 11, 2026
170 checks passed
@sentrivana
sentrivana deleted the pablo/aws-lambda-load-handler-once branch November 11, 2026 10:01
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

2 participants