File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,8 +40,8 @@ def load_nested_zip() -> None:
4040 # [No longer applicable] We want our path to look like [working_dir, /tmp/package-python-function, ...]
4141 # Refer to https://docs.aws.amazon.com/lambda/latest/dg/python-package.html#python-package-searchpath
4242 # We need to replace the original path that AWS Lambda setup for us.
43- # sys.path.insert(1, target_package_path)
44- sys .path [0 ] = target_package_path
43+ # sys.path.insert(1, str( target_package_path) )
44+ sys .path [0 ] = str ( target_package_path )
4545 importlib .reload (sys .modules [__name__ ])
4646
4747load_nested_zip ()
Original file line number Diff line number Diff line change 1+ import importlib
2+ from pathlib import Path
3+ import sys
4+ import zipfile
5+
6+
7+ def xtest_local (package_path : str , entrypoint : str ) -> None :
8+ output_path = Path (package_path ).parent / 'lambda'
9+ output_path .mkdir (parents = True , exist_ok = True )
10+ with zipfile .ZipFile (package_path , 'r' ) as zip :
11+ zip .extractall (str (output_path ))
12+
13+ sys .path .insert (0 , str (output_path ))
14+
15+ entrypoint_parts = entrypoint .split ('.' )
16+ module_name = '.' .join (entrypoint_parts [0 :1 ])
17+ entry_function = entrypoint_parts [2 ]
18+ module = importlib .import_module (module_name )
19+ print (sys .path )
20+ module .__dict__ [entry_function ]()
21+
22+
23+ if __name__ == '__main__' :
24+ xtest_local (sys .argv [1 ], sys .argv [2 ])
You can’t perform that action at this time.
0 commit comments