8000 fix lambda function extra resources upload in s3 (#11655) · localstack/localstack@4a775c4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a775c4

Browse files
authored
fix lambda function extra resources upload in s3 (#11655)
1 parent 132b968 commit 4a775c4

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

localstack-core/localstack/testing/scenario/cdk_lambda_helper.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def load_nodejs_lambda_to_s3(
6969
key_name: str,
7070
code_path: str,
7171
additional_nodjs_packages: list[str] = None,
72+
additional_nodejs_packages: list[str] = None,
7273
additional_resources: list[str] = None,
7374
):
7475
"""
@@ -81,39 +82,40 @@ def load_nodejs_lambda_to_s3(
8182
:param key_name: key name for the uploaded zip file
8283
:param code_path: the path to the source code that should be included
8384
: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
8486
:param additional_resources: list of path-strings to resources or internal libs that should be packaged into the lambda
8587
:return: None
8688
"""
8789
additional_resources = additional_resources or []
8890

91+
if additional_nodjs_packages:
92+
additional_nodejs_packages = additional_nodejs_packages or []
93+
additional_nodejs_packages.extend(additional_nodjs_packages)
94+
8995
try:
9096
temp_dir = tempfile.mkdtemp()
9197
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:
94101
try:
95102
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)} ")
97104
except Exception as e:
98105
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
100107
)
101108

102109
for r in additional_resources:
103110
try:
104-
path = Path(os.path.join(r))
111+
path = Path(r)
105112
if path.is_dir():
106113
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)
114116
elif path.is_file():
115117
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)
117119
except Exception as e:
118120
LOG.error("Could not copy additional resources %s: %s", r, e)
119121

0 commit comments

Comments
 (0)
0