11
11
import traceback
12
12
13
13
from .lambda_context import LambdaContext
14
- from .lambda_runtime_client import LambdaRuntimeClient
15
14
from .lambda_runtime_exception import FaultException
16
15
from .lambda_runtime_log_utils import (
17
16
_DATETIME_FORMAT ,
@@ -158,7 +157,6 @@ def handle_event_request(
158
157
cognito_identity_json ,
159
158
invoked_function_arn ,
160
159
epoch_deadline_time_in_ms ,
161
- tenant_id ,
162
160
log_sink ,
163
161
):
164
162
error_result = None
@@ -169,7 +167,6 @@ def handle_event_request(
169
167
epoch_deadline_time_in_ms ,
170
168
invoke_id ,
171
169
invoked_function_arn ,
172
- tenant_id ,
173
170
)
174
171
event = lambda_runtime_client .marshaller .unmarshal_request (
175
172
event_body , content_type
@@ -201,7 +198,9 @@ def handle_event_request(
201
198
)
202
199
203
200
if error_result is not None :
201
+ from .lambda_literals import lambda_unhandled_exception_warning_message
204
202
203
+ logging .warning (lambda_unhandled_exception_warning_message )
205
204
log_error (error_result , log_sink )
206
205
lambda_runtime_client .post_invocation_error (
207
206
invoke_id , to_json (error_result ), to_json (xray_fault )
@@ -229,7 +228,6 @@ def create_lambda_context(
229
228
epoch_deadline_time_in_ms ,
230
229
invoke_id ,
231
230
invoked_function_arn ,
232
- tenant_id ,
233
231
):
234
232
client_context = None
235
233
if client_context_json :
@@ -244,7 +242,6 @@ def create_lambda_context(
244
242
cognito_identity ,
245
243
epoch_deadline_time_in_ms ,
246
244
invoked_function_arn ,
247
- tenant_id ,
248
245
)
249
246
250
247
@@ -339,7 +336,6 @@ def emit(self, record):
339
336
class LambdaLoggerFilter (logging .Filter ):
340
337
def filter (self , record ):
341
338
record .aws_request_id = _GLOBAL_AWS_REQUEST_ID or ""
342
- record .tenant_id = _GLOBAL_TENANT_ID
343
339
return True
344
340
345
341
@@ -448,7 +444,6 @@ def create_log_sink():
448
444
449
445
450
446
_GLOBAL_AWS_REQUEST_ID = None
451
- _GLOBAL_TENANT_ID = None
452
447
453
448
454
449
def _setup_logging (log_format , log_level , log_sink ):
@@ -487,16 +482,17 @@ def run(app_root, handler, lambda_runtime_api_addr):
487
482
}
488
483
489
484
with create_log_sink () as log_sink :
490
- lambda_runtime_client = LambdaRuntimeClient (
491
- lambda_runtime_api_addr , use_thread_for_polling_next
492
- )
493
485
error_result = None
494
486
495
487
try :
496
488
_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
498
490
499
491
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 )
500
496
except FaultException as e :
501
497
error_result = make_error (
502
498
e .msg ,
@@ -505,11 +501,8 @@ def run(app_root, handler, lambda_runtime_api_addr):
505
501
)
506
502
except Exception :
507
503
error_result = build_fault_result (sys .exc_info (), None )
508
-
504
+
509
505
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 )
513
506
log_error (error_result , log_sink )
514
507
lambda_runtime_client .post_init_error (error_result )
515
508
@@ -522,7 +515,6 @@ def run(app_root, handler, lambda_runtime_api_addr):
522
515
event_request = lambda_runtime_client .wait_next_invocation ()
523
516
524
517
_GLOBAL_AWS_REQUEST_ID = event_request .invoke_id
525
- _GLOBAL_TENANT_ID = event_request .tenant_id
526
518
527
519
update_xray_env_variable (event_request .x_amzn_trace_id )
528
520
@@ -536,6 +528,5 @@ def run(app_root, handler, lambda_runtime_api_addr):
536
528
event_request .cognito_identity ,
537
529
event_request .invoked_function_arn ,
538
530
event_request .deadline_time_in_ms ,
539
- event_request .tenant_id ,
540
531
log_sink ,
541
532
)
0 commit comments