Best Python code snippet using localstack_python
lambda_api.py
Source:lambda_api.py
...393 return result394 return execute395 raise ClientError(error_response(396 'Unable to extract Java Lambda handler - file is not a valid zip/jar files', 400, error_type='ValidationError'))397def set_archive_code(code, lambda_name, zip_file_content=None):398 # get metadata399 lambda_arn = func_arn(lambda_name)400 lambda_details = arn_to_lambda[lambda_arn]401 is_local_mount = code.get('S3Bucket') == BUCKET_MARKER_LOCAL402 # Stop/remove any containers that this arn uses.403 LAMBDA_EXECUTOR.cleanup(lambda_arn)404 if is_local_mount:405 # Mount or use a local folder lambda executors can reference406 # WARNING: this means we're pointing lambda_cwd to a local path in the user's407 # file system! We must ensure that there is no data loss (i.e., we must *not* add408 # this folder to TMP_FILES or similar).409 return code['S3Key']410 # get file content411 zip_file_content = zip_file_content or get_zip_bytes(code)412 # Save the zip file to a temporary file that the lambda executors can reference413 code_sha_256 = base64.standard_b64encode(hashlib.sha256(zip_file_content).digest())414 lambda_details.get_version('$LATEST')['CodeSize'] = len(zip_file_content)415 lambda_details.get_version('$LATEST')['CodeSha256'] = code_sha_256.decode('utf-8')416 tmp_dir = '%s/zipfile.%s' % (config.TMP_FOLDER, short_uid())417 mkdir(tmp_dir)418 tmp_file = '%s/%s' % (tmp_dir, LAMBDA_ZIP_FILE_NAME)419 save_file(tmp_file, zip_file_content)420 TMP_FILES.append(tmp_dir)421 lambda_details.cwd = tmp_dir422 return tmp_dir423def set_function_code(code, lambda_name, lambda_cwd=None):424 def generic_handler(event, context):425 raise ClientError(('Unable to find executor for Lambda function "%s". Note that ' +426 'Node.js, Golang, and .Net Core Lambdas currently require LAMBDA_EXECUTOR=docker') % lambda_name)427 arn = func_arn(lambda_name)428 lambda_details = arn_to_lambda[arn]429 runtime = lambda_details.runtime430 lambda_environment = lambda_details.envvars431 handler_name = lambda_details.handler or LAMBDA_DEFAULT_HANDLER432 code_passed = code433 code = code or lambda_details.code434 is_local_mount = code.get('S3Bucket') == BUCKET_MARKER_LOCAL435 zip_file_content = None436 if code_passed:437 lambda_cwd = lambda_cwd or set_archive_code(code_passed, lambda_name)438 if not is_local_mount:439 # Save the zip file to a temporary file that the lambda executors can reference440 zip_file_content = get_zip_bytes(code_passed)441 else:442 lambda_cwd = lambda_cwd or lambda_details.cwd443 # get local lambda working directory444 tmp_file = '%s/%s' % (lambda_cwd, LAMBDA_ZIP_FILE_NAME)445 if not zip_file_content:446 zip_file_content = load_file(tmp_file, mode='rb')447 # Set the appropriate lambda handler.448 lambda_handler = generic_handler449 if runtime == LAMBDA_RUNTIME_JAVA8:450 # The Lambda executors for Docker subclass LambdaExecutorContainers,451 # which runs Lambda in Docker by passing all *.jar files in the function...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!