Skip to content

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

Closed
ansh-rohilla wants to merge 1 commit into
getsentry:masterfrom
ansh-rohilla:fix/aws-lambda-load-handler-once-8079
Closed

ansh-rohilla wants to merge 1 commit into
getsentry:masterfrom
ansh-rohilla:fix/aws-lambda-load-handler-once-8079

Conversation

@ansh-rohilla

Copy link
Copy Markdown

Description

In sentry_lambda_layer (scripts/init_serverless_sdk.py), sentry_lambda_handler was constructing a new AWSLambdaModuleLoader on every invocation. This caused extract_and_load_lambda_function_module to run repeatedly, re-importing or re-executing the module on every warm invocation.

This change caches the resolved AWSLambdaModuleLoader and entry point handler at module scope upon first invocation so subsequent invocations reuse the cached handler directly. Added unit tests covering cached handler reuse across multiple invocations, handler execution, and loader reset.

Issues

…y#8079)

Cache the resolved AWSLambdaModuleLoader and entry point handler at module scope in init_serverless_sdk so subsequent Lambda invocations reuse the cached handler without re-importing or re-executing the module on each invocation.

Closes getsentry#8079
@ansh-rohilla
ansh-rohilla requested a review from a team as a code owner October 26, 2026 17:28
@pabloDeputter

Copy link
Copy Markdown
Member

Thanks for picking this up! Closing it since we're already working on it and be put up for review this week. This fix itself can be done using a single cached _lambda_handler, _module_loader is also set and never read. Some of the proposed tests are also passing without the fix in place.

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