From 465773ac75ac9e13f81bd15f0f17f30ea8760c5e Mon Sep 17 00:00:00 2001 From: Frank Chiang Date: Thu, 6 Jan 2022 14:27:51 -0500 Subject: [PATCH] Update handler to be global if INSTANTIATE_LAMBDA_HANDLER_ON_IMPORT=True (#1096) * Update handler to be global if INSTANTIATE_LAMBDA_HANDLER_ON_IMPORT=True * Replace global Co-authored-by: Frank Chiang Co-authored-by: javulticat <31746850+javulticat@users.noreply.github.com> --- zappa/handler.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zappa/handler.py b/zappa/handler.py index 53c57be84..f7c82b635 100644 --- a/zappa/handler.py +++ b/zappa/handler.py @@ -246,8 +246,7 @@ def import_module_and_get_function(whole_function): @classmethod def lambda_handler(cls, event, context): # pragma: no cover - if not os.environ.get("INSTANTIATE_LAMBDA_HANDLER_ON_IMPORT"): - handler = cls() + handler = global_handler or cls() exception_handler = handler.settings.EXCEPTION_HANDLER try: return handler.handler(event, context) @@ -664,5 +663,6 @@ def keep_warm_callback(event, context): # be triggered. +global_handler = None if os.environ.get("INSTANTIATE_LAMBDA_HANDLER_ON_IMPORT"): - handler = LambdaHandler() + global_handler = LambdaHandler()