Skip to content

Commit 5cb3029

Browse files
committed
Lazily initialize http modules used for error handling
1 parent b42d267 commit 5cb3029

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

awslambdaric/lambda_runtime_client.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
"""
44

5-
import http
6-
import http.client
75
import sys
86
from awslambdaric import __version__
97

@@ -54,6 +52,11 @@ def __init__(self, lambda_runtime_address):
5452
self.lambda_runtime_address = lambda_runtime_address
5553

5654
def post_init_error(self, error_response_data):
55+
# These imports are heavy-weight. They implicitly trigger `import ssl, hashlib`.
56+
# Importing them lazily to speed up critical path of a common case.
57+
import http
58+
import http.client
59+
5760
runtime_connection = http.client.HTTPConnection(self.lambda_runtime_address)
5861
runtime_connection.connect()
5962
endpoint = "/2018-06-01/runtime/init/error"

0 commit comments

Comments
 (0)