@@ -69,6 +69,7 @@ def load_nodejs_lambda_to_s3(
69
69
key_name : str ,
70
70
code_path : str ,
71
71
additional_nodjs_packages : list [str ] = None ,
72
+ additional_nodejs_packages : list [str ] = None ,
72
73
additional_resources : list [str ] = None ,
73
74
):
74
75
"""
@@ -81,39 +82,40 @@ def load_nodejs_lambda_to_s3(
81
82
:param key_name: key name for the uploaded zip file
82
83
:param code_path: the path to the source code that should be included
83
84
:param additional_nodjs_packages: a list of strings with nodeJS packages that are required to run the lambda
85
+ :param additional_nodejs_packages: a list of strings with nodeJS packages that are required to run the lambda
84
86
:param additional_resources: list of path-strings to resources or internal libs that should be packaged into the lambda
85
87
:return: None
86
88
"""
87
89
additional_resources = additional_resources or []
88
90
91
+ if additional_nodjs_packages :
92
+ additional_nodejs_packages = additional_nodejs_packages or []
93
+ additional_nodejs_packages .extend (additional_nodjs_packages )
94
+
89
95
try :
90
96
temp_dir = tempfile .mkdtemp ()
91
97
tmp_zip_path = os .path .join (tempfile .gettempdir (), "helper.zip" )
92
- # install python packages
93
- if additional_nodjs_packages :
98
+
99
+ # Install NodeJS packages
100
+ if additional_nodejs_packages :
94
101
try :
95
102
os .mkdir (os .path .join (temp_dir , "node_modules" ))
96
- run (f"cd { temp_dir } && npm install { ' ' .join (additional_nodjs_packages )} " )
103
+ run (f"cd { temp_dir } && npm install { ' ' .join (additional_nodejs_packages )} " )
97
104
except Exception as e :
98
105
LOG .error (
99
- "Could not install additional packages %s: %s" , additional_nodjs_packages , e
106
+ "Could not install additional packages %s: %s" , additional_nodejs_packages , e
100
107
)
101
108
102
109
for r in additional_resources :
103
110
try :
104
- path = Path (os . path . join ( r ) )
111
+ path = Path (r )
105
112
if path .is_dir ():
106
113
dir_name = os .path .basename (path )
107
- os .mkdir (os .path .join (temp_dir , dir_name ))
108
- for filename in os .listdir (path ):
109
- f = os .path .join (path , filename )
110
- # checking if it is a file
111
- if os .path .isfile (f ):
112
- new_resource_temp_path = os .path .join (temp_dir , dir_name , filename )
113
- shutil .copy2 (f , new_resource_temp_path )
114
+ dest_dir = os .path .join (temp_dir , dir_name )
115
+ shutil .copytree (path , dest_dir )
114
116
elif path .is_file ():
115
117
new_resource_temp_path = os .path .join (temp_dir , os .path .basename (path ))
116
- shutil .copy2 (os . path . join ( r ) , new_resource_temp_path )
118
+ shutil .copy2 (path , new_resource_temp_path )
117
119
except Exception as e :
118
120
LOG .error ("Could not copy additional resources %s: %s" , r , e )
119
121
0 commit comments