🐛 Skip keep-warm import of handler.keep_warm_callback (#1469) - #1470
Open
dennybiasiolli wants to merge 2 commits into
Open
🐛 Skip keep-warm import of handler.keep_warm_callback (#1469)#1470dennybiasiolli wants to merge 2 commits into
dennybiasiolli wants to merge 2 commits into
Conversation
Keep-warm EventBridge rules encode handler.keep_warm_callback. Importing that path fails when there is no zip-root handler.py (custom lambda_handler / container deploys). LambdaHandler construction already loaded the app, so return without importing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1469.
When
keep_warmis on (the default), Zappa schedules an EventBridge rule whose target is hardcoded ashandler.keep_warm_callback. On invoke,LambdaHandlertreats that string as an import path. That works for a classic zip (the package copieszappa/handler.pyto the archive root ashandler.py). It fails for a customlambda_handler/ container image that has no top-levelhandlermodule:HTTP can still succeed. The keep-warm ping fails every few minutes.
Fix
In the Scheduled Event branch, if the extracted function name ends in
keep_warm_callback, return afterLambdaHandlerconstruction. Do not importhandler.keep_warm_callback.functioncannot contain hyphens, sosplit("-")[-1]is the full dotted path).keep_warm_callbackre-entry (lambda_handler(event={})) was not load-bearing:__init__already loads the app.The CLI still schedules
handler.keep_warm_callback. Changing that string would rename the rule and would not fix existing rules.Test plan
test_keep_warm_scheduled_event_without_handler_module— Scheduled Event whose rule ARN ends inzappa-keep-warm-handler.keep_warm_callback, with no top-levelhandlermodule, must not raiseModuleNotFoundError. Fails without the special-case, passes with it.test_scheduled_event_invokes_target_function— a real scheduled target (tests.test_app.schedule_me) still imports and runs.tests/test_handler.pytests pass;black,isort,flake8clean on touched Python.Fixes #1469