38
38
event_source_arn_matches ,
39
39
get_executor_mode ,
40
40
get_handler_file_from_name ,
41
+ get_lambda_extraction_dir ,
41
42
get_lambda_runtime ,
42
43
get_zip_bytes ,
43
44
multi_value_dict_for_list ,
@@ -709,13 +710,16 @@ def set_archive_code(code: Dict, lambda_name: str, zip_file_content: bytes = Non
709
710
latest_version = lambda_details .get_version (VERSION_LATEST )
710
711
latest_version ["CodeSize" ] = len (zip_file_content )
711
712
latest_version ["CodeSha256" ] = code_sha_256 .decode ("utf-8" )
712
- tmp_dir = "%s/zipfile.%s" % (config .dirs .tmp , short_uid ())
713
- mkdir (tmp_dir )
714
- tmp_file = "%s/%s" % (tmp_dir , LAMBDA_ZIP_FILE_NAME )
713
+ zip_dir_name = f"function.zipfile.{ short_uid ()} "
714
+ zip_dir = f"{ config .dirs .tmp } /{ zip_dir_name } "
715
+ mkdir (zip_dir )
716
+ tmp_file = f"{ zip_dir } /{ LAMBDA_ZIP_FILE_NAME } "
715
717
save_file (tmp_file , zip_file_content )
716
- TMP_FILES .append (tmp_dir )
717
- lambda_details .cwd = tmp_dir
718
- return tmp_dir
718
+ TMP_FILES .append (zip_dir )
719
+ lambda_details .zip_dir = zip_dir
720
+ lambda_details .cwd = f"{ get_lambda_extraction_dir ()} /{ zip_dir_name } "
721
+ mkdir (lambda_details .cwd )
722
+ return zip_dir
719
723
720
724
721
725
def set_function_code (lambda_function : LambdaFunction ):
@@ -749,22 +753,22 @@ def store_and_get_lambda_code_archive(
749
753
in case this is a Lambda with the special bucket marker __local__, used for code mounting."""
750
754
code_passed = lambda_function .code
751
755
is_local_mount = code_passed .get ("S3Bucket" ) == config .BUCKET_MARKER_LOCAL
752
- lambda_cwd = lambda_function .cwd
756
+ lambda_zip_dir = lambda_function .zip_dir
753
757
754
758
if code_passed :
755
- lambda_cwd = lambda_cwd or set_archive_code (code_passed , lambda_function .name ())
759
+ lambda_zip_dir = lambda_zip_dir or set_archive_code (code_passed , lambda_function .name ())
756
760
if not zip_file_content and not is_local_mount :
757
761
# Save the zip file to a temporary file that the lambda executors can reference
758
762
zip_file_content = get_zip_bytes (code_passed )
759
763
else :
760
764
lambda_details = LambdaRegion .get ().lambdas [lambda_function .arn ()]
761
- lambda_cwd = lambda_cwd or lambda_details .cwd
765
+ lambda_zip_dir = lambda_zip_dir or lambda_details .zip_dir
762
766
763
- if not lambda_cwd :
767
+ if not lambda_zip_dir :
764
768
return
765
769
766
770
# construct archive name
767
- archive_file = os .path .join (lambda_cwd , LAMBDA_ZIP_FILE_NAME )
771
+ archive_file = os .path .join (lambda_zip_dir , LAMBDA_ZIP_FILE_NAME )
768
772
769
773
if not zip_file_content :
770
774
zip_file_content = load_file (archive_file , mode = "rb" )
@@ -773,7 +777,7 @@ def store_and_get_lambda_code_archive(
773
777
save_file (archive_file , zip_file_content )
774
778
# remove content from code attribute, if present
775
779
lambda_function .code .pop ("ZipFile" , None )
776
- return lambda_cwd , archive_file , zip_file_content
780
+ return lambda_zip_dir , archive_file , zip_file_content
777
781
778
782
779
783
def do_set_function_code (lambda_function : LambdaFunction ):
@@ -804,7 +808,8 @@ def generic_handler(*_):
804
808
_result = store_and_get_lambda_code_archive (lambda_function )
805
809
if not _result :
806
810
return
807
- lambda_cwd , archive_file , zip_file_content = _result
811
+ lambda_zip_dir , archive_file , zip_file_content = _result
812
+ lambda_cwd = lambda_function .cwd
808
813
809
814
# Set the appropriate Lambda handler.
810
815
lambda_handler = generic_handler
@@ -841,19 +846,15 @@ def generic_handler(*_):
841
846
# Obtain handler details for any non-Java Lambda function
842
847
if not is_java :
843
848
handler_file = get_handler_file_from_name (handler_name , runtime = runtime )
844
- main_file = "%s/%s" % ( lambda_cwd , handler_file )
849
+ main_file = f" { lambda_cwd } / { handler_file } "
845
850
846
851
if CHECK_HANDLER_ON_CREATION and not os .path .exists (main_file ):
847
852
# Raise an error if (1) this is not a local mount lambda, or (2) we're
848
853
# running Lambdas locally (not in Docker), or (3) we're using remote Docker.
849
854
# -> We do *not* want to raise an error if we're using local mount in non-remote Docker
850
855
if not is_local_mount or not use_docker () or config .LAMBDA_REMOTE_DOCKER :
851
- file_list = run ('cd "%s"; du -d 3 .' % lambda_cwd )
852
- config_debug = 'Config for local mount, docker, remote: "%s", "%s", "%s"' % (
853
- is_local_mount ,
854
- use_docker (),
855
- config .LAMBDA_REMOTE_DOCKER ,
856
- )
856
+ file_list = run (f'cd "{ lambda_cwd } "; du -d 3 .' )
857
+ config_debug = f'Config for local mount, docker, remote: "{ is_local_mount } ", "{ use_docker ()} ", "{ config .LAMBDA_REMOTE_DOCKER } "'
857
858
LOG .debug ("Lambda archive content:\n %s" , file_list )
858
859
raise ClientError (
859
860
error_response (
@@ -1277,27 +1278,6 @@ def update_function_code(function):
1277
1278
return jsonify (result or {})
1278
1279
1279
1280
1280
- @app .route ("%s/functions/<function>/code" % API_PATH_ROOT , methods = ["GET" ])
1281
- def get_function_code (function ):
1282
- """Get the code of an existing function
1283
- ---
1284
- operationId: 'getFunctionCode'
1285
- parameters:
1286
- """
1287
- region = LambdaRegion .get ()
1288
- arn = func_arn (function )
1289
- lambda_function = region .lambdas .get (arn )
1290
- if not lambda_function :
1291
- return not_found_error (arn )
1292
- lambda_cwd = lambda_function .cwd
1293
- tmp_file = "%s/%s" % (lambda_cwd , LAMBDA_ZIP_FILE_NAME )
1294
- return Response (
1295
- load_file (tmp_file , mode = "rb" ),
1296
- mimetype = "application/zip" ,
1297
- headers = {"Content-Disposition" : "attachment; filename=lambda_archive.zip" },
1298
- )
1299
-
1300
-
1301
1281
@app .route ("%s/functions/<function>/configuration" % API_PATH_ROOT , methods = ["GET" ])
1302
1282
def get_function_configuration (function ):
1303
1283
"""Get the configuration of an existing function
0 commit comments