-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_lambda_package.py
40 lines (33 loc) · 1.17 KB
/
create_lambda_package.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import shutil
import subprocess
import sys
lambda_dir = f'{os.path.dirname(os.path.realpath(__file__))}'
task_dir = f'{lambda_dir}/task'
temp_dir = f'{lambda_dir}/temp'
print(f'Installing package requirements...')
# Install requirements
os.makedirs(temp_dir, exist_ok=True)
subprocess.check_call([sys.executable, '-m', 'pip', 'install',
'-r', 'requirements.txt', '--target', temp_dir,
'--force-reinstall'], stdout=sys.__stdout__)
print('Installation complete...')
print('Copying source files...')
# Copy source files
dest_dir = f'{temp_dir}/task/'
os.makedirs(dest_dir, exist_ok=True)
for ele in os.listdir(task_dir):
print(ele)
if ele.endswith('.py'):
src_file = f'{task_dir}/{ele}'
print(f'copying [src, dest]: [{src_file}, {dest_dir}]')
result = shutil.copy(src_file, dest_dir)
print(result)
print('Copying complete...')
print('Creating lambda zip archive...')
# Make archive and cleanup temp directory
shutil.make_archive(f'{lambda_dir}/opensearch_package', 'zip', temp_dir)
print('Archive creation complete...')
print('Cleaning up temp directory...')
shutil.rmtree(temp_dir)
print('Complete')