1111import traceback
1212
1313from .lambda_context import LambdaContext
14- from .lambda_runtime_client import LambdaRuntimeClient
1514from .lambda_runtime_exception import FaultException
1615from .lambda_runtime_log_utils import (
1716 _DATETIME_FORMAT ,
@@ -158,7 +157,6 @@ def handle_event_request(
158157 cognito_identity_json ,
159158 invoked_function_arn ,
160159 epoch_deadline_time_in_ms ,
161- tenant_id ,
162160 log_sink ,
163161):
164162 error_result = None
@@ -169,7 +167,6 @@ def handle_event_request(
169167 epoch_deadline_time_in_ms ,
170168 invoke_id ,
171169 invoked_function_arn ,
172- tenant_id ,
173170 )
174171 event = lambda_runtime_client .marshaller .unmarshal_request (
175172 event_body , content_type
@@ -201,7 +198,9 @@ def handle_event_request(
201198 )
202199
203200 if error_result is not None :
201+ from .lambda_literals import lambda_unhandled_exception_warning_message
204202
203+ logging .warning (lambda_unhandled_exception_warning_message )
205204 log_error (error_result , log_sink )
206205 lambda_runtime_client .post_invocation_error (
207206 invoke_id , to_json (error_result ), to_json (xray_fault )
@@ -229,7 +228,6 @@ def create_lambda_context(
229228 epoch_deadline_time_in_ms ,
230229 invoke_id ,
231230 invoked_function_arn ,
232- tenant_id ,
233231):
234232 client_context = None
235233 if client_context_json :
@@ -244,7 +242,6 @@ def create_lambda_context(
244242 cognito_identity ,
245243 epoch_deadline_time_in_ms ,
246244 invoked_function_arn ,
247- tenant_id ,
248245 )
249246
250247
@@ -339,7 +336,6 @@ def emit(self, record):
339336class LambdaLoggerFilter (logging .Filter ):
340337 def filter (self , record ):
341338 record .aws_request_id = _GLOBAL_AWS_REQUEST_ID or ""
342- record .tenant_id = _GLOBAL_TENANT_ID
343339 return True
344340
345341
@@ -448,7 +444,6 @@ def create_log_sink():
448444
449445
450446_GLOBAL_AWS_REQUEST_ID = None
451- _GLOBAL_TENANT_ID = None
452447
453448
454449def _setup_logging (log_format , log_level , log_sink ):
@@ -487,16 +482,17 @@ def run(app_root, handler, lambda_runtime_api_addr):
487482 }
488483
489484 with create_log_sink () as log_sink :
490- lambda_runtime_client = LambdaRuntimeClient (
491- lambda_runtime_api_addr , use_thread_for_polling_next
492- )
493485 error_result = None
494486
495487 try :
496488 _setup_logging (_AWS_LAMBDA_LOG_FORMAT , _AWS_LAMBDA_LOG_LEVEL , log_sink )
497- global _GLOBAL_AWS_REQUEST_ID , _GLOBAL_TENANT_ID
489+ global _GLOBAL_AWS_REQUEST_ID
498490
499491 request_handler = _get_handler (handler )
492+
493+ # import and initialize the LambdaRuntimeClient lazily.
494+ from .lambda_runtime_client import LambdaRuntimeClient
495+ lambda_runtime_client = LambdaRuntimeClient (lambda_runtime_api_addr , use_thread_for_polling_next )
500496 except FaultException as e :
501497 error_result = make_error (
502498 e .msg ,
@@ -505,11 +501,8 @@ def run(app_root, handler, lambda_runtime_api_addr):
505501 )
506502 except Exception :
507503 error_result = build_fault_result (sys .exc_info (), None )
508-
504+
509505 if error_result is not None :
510- from .lambda_literals import lambda_unhandled_exception_warning_message
511-
512- logging .warning (lambda_unhandled_exception_warning_message )
513506 log_error (error_result , log_sink )
514507 lambda_runtime_client .post_init_error (error_result )
515508
@@ -522,7 +515,6 @@ def run(app_root, handler, lambda_runtime_api_addr):
522515 event_request = lambda_runtime_client .wait_next_invocation ()
523516
524517 _GLOBAL_AWS_REQUEST_ID = event_request .invoke_id
525- _GLOBAL_TENANT_ID = event_request .tenant_id
526518
527519 update_xray_env_variable (event_request .x_amzn_trace_id )
528520
@@ -536,6 +528,5 @@ def run(app_root, handler, lambda_runtime_api_addr):
536528 event_request .cognito_identity ,
537529 event_request .invoked_function_arn ,
538530 event_request .deadline_time_in_ms ,
539- event_request .tenant_id ,
540531 log_sink ,
541532 )
0 commit comments