Skip to content

🐛 Skip keep-warm import of handler.keep_warm_callback (#1469) - #1470

Open
dennybiasiolli wants to merge 2 commits into
zappa:masterfrom
dennybiasiolli:fix/1469-keep-warm-handler-import
Open

🐛 Skip keep-warm import of handler.keep_warm_callback (#1469)#1470
dennybiasiolli wants to merge 2 commits into
zappa:masterfrom
dennybiasiolli:fix/1469-keep-warm-handler-import

Conversation

@dennybiasiolli

Copy link
Copy Markdown
Contributor

Summary

Fixes #1469.

When keep_warm is on (the default), Zappa schedules an EventBridge rule whose target is hardcoded as handler.keep_warm_callback. On invoke, LambdaHandler treats that string as an import path. That works for a classic zip (the package copies zappa/handler.py to the archive root as handler.py). It fails for a custom lambda_handler / container image that has no top-level handler module:

ModuleNotFoundError: No module named 'handler'

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 after LambdaHandler construction. Do not import handler.keep_warm_callback.

  • Existing EventBridge rules keep their current name, so this fixes production on the next code deploy.
  • Classic zip deploys are unchanged.
  • User-configured scheduled functions still import and run (function cannot contain hyphens, so split("-")[-1] is the full dotted path).
  • The extra keep_warm_callback re-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 in zappa-keep-warm-handler.keep_warm_callback, with no top-level handler module, must not raise ModuleNotFoundError. 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.
  • All 28 tests/test_handler.py tests pass; black, isort, flake8 clean on touched Python.

Fixes #1469

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.
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 74.816% (+0.03%) from 74.785% — dennybiasiolli:fix/1469-keep-warm-handler-import into zappa:master

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.

keep_warm raises No module named 'handler' when there is no zip-root handler.py

2 participants