MCPcopy Index your code
hub / github.com/zappa/Zappa / create_package

Method create_package

zappa/cli.py:2929–3012  ·  view source on GitHub ↗

Ensure that the package can be properly configured, and then create it.

(self, output=None, use_zappa_release: Optional[str] = None)

Source from the content-addressed store, hash-verified

2927 )
2928
2929 def create_package(self, output=None, use_zappa_release: Optional[str] = None):
2930 """
2931 Ensure that the package can be properly configured,
2932 and then create it.
2933 """
2934
2935 # Create the Lambda zip package (includes project and virtualenvironment)
2936 # Also define the path the handler file so it can be copied to the zip
2937 # root for Lambda.
2938 current_file = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) # type: ignore[arg-type]
2939 handler_file = os.sep.join(current_file.split(os.sep)[0:]) + os.sep + "handler.py"
2940
2941 # Create the zip file(s)
2942 if self.stage_config.get("slim_handler", False):
2943 # Create two zips. One with the application and the other with just the handler.
2944 # https://github.com/Miserlou/Zappa/issues/510
2945 self.zip_path = self.zappa.create_lambda_zip( # type: ignore[attr-defined]
2946 prefix=self.lambda_name,
2947 use_precompiled_packages=self.stage_config.get("use_precompiled_packages", True),
2948 exclude=self.stage_config.get("exclude", []),
2949 exclude_glob=self.stage_config.get("exclude_glob", []),
2950 disable_progress=self.disable_progress,
2951 archive_format="tarball",
2952 )
2953
2954 # Make sure the normal venv is not included in the handler's zip
2955 exclude = self.stage_config.get("exclude", [])
2956 cur_venv = self.zappa.get_current_venv() # type: ignore[attr-defined]
2957 exclude.append(cur_venv.name)
2958 self.handler_path = self.zappa.create_lambda_zip( # type: ignore[attr-defined]
2959 prefix="handler_{0!s}".format(self.lambda_name),
2960 venv=self.zappa.create_handler_venv(use_zappa_release=use_zappa_release), # type: ignore[attr-defined]
2961 handler_file=handler_file,
2962 slim_handler=True,
2963 exclude=exclude,
2964 exclude_glob=self.stage_config.get("exclude_glob", []),
2965 output=output,
2966 disable_progress=self.disable_progress,
2967 )
2968 else:
2969 exclude = self.stage_config.get("exclude", [])
2970
2971 # Create a single zip that has the handler and application
2972 self.zip_path = self.zappa.create_lambda_zip( # type: ignore[attr-defined]
2973 prefix=self.lambda_name,
2974 handler_file=handler_file,
2975 use_precompiled_packages=self.stage_config.get("use_precompiled_packages", True),
2976 exclude=exclude,
2977 exclude_glob=self.stage_config.get("exclude_glob", []),
2978 output=output,
2979 disable_progress=self.disable_progress,
2980 )
2981
2982 # Warn if this is too large for Lambda.
2983 file_stats = os.stat(self.zip_path)
2984 if file_stats.st_size > 52428800: # pragma: no cover
2985 print(
2986 "\n\nWarning: Application zip package is likely to be too large for AWS Lambda. "

Callers 8

packageMethod · 0.95
deployMethod · 0.95
updateMethod · 0.95
test_cli_utilityMethod · 0.95
test_slim_handlerMethod · 0.95

Calls 4

create_lambda_zipMethod · 0.80
get_current_venvMethod · 0.80
create_handler_venvMethod · 0.80

Tested by 5

test_cli_utilityMethod · 0.76
test_slim_handlerMethod · 0.76