Create a Lambda-ready zip file of the current virtualenvironment and working directory. Returns path to that file.
(
self,
prefix="lambda_package",
handler_file=None,
slim_handler=False,
minify=True,
exclude=None,
exclude_glob=None,
use_precompiled_packages=True,
include=None,
venv=None,
output=None,
disable_progress=False,
archive_format="zip",
)
| 476 | return None |
| 477 | |
| 478 | def create_lambda_zip( |
| 479 | self, |
| 480 | prefix="lambda_package", |
| 481 | handler_file=None, |
| 482 | slim_handler=False, |
| 483 | minify=True, |
| 484 | exclude=None, |
| 485 | exclude_glob=None, |
| 486 | use_precompiled_packages=True, |
| 487 | include=None, |
| 488 | venv=None, |
| 489 | output=None, |
| 490 | disable_progress=False, |
| 491 | archive_format="zip", |
| 492 | ) -> str: |
| 493 | """ |
| 494 | Create a Lambda-ready zip file of the current virtualenvironment and working directory. |
| 495 | Returns path to that file. |
| 496 | """ |
| 497 | # Validate archive_format |
| 498 | if archive_format not in ["zip", "tarball"]: |
| 499 | raise KeyError("The archive format to create a lambda package must be zip or tarball") |
| 500 | |
| 501 | # Pip is a weird package. |
| 502 | # Calling this function in some environments without this can cause.. funkiness. |
| 503 | import pip # noqa: 547 |
| 504 | |
| 505 | if not venv: |
| 506 | venv = self.get_current_venv() |
| 507 | |
| 508 | build_time = str(int(time.time())) |
| 509 | cwd = Path.cwd() |
| 510 | if not output: |
| 511 | if archive_format == "zip": |
| 512 | archive_fname = f"{prefix}-{build_time}.zip" |
| 513 | elif archive_format == "tarball": |
| 514 | archive_fname = f"{prefix}-{build_time}.tar.gz" |
| 515 | else: |
| 516 | archive_fname = output |
| 517 | archive_path = cwd / archive_fname |
| 518 | |
| 519 | # Files that should be excluded from the zip |
| 520 | if exclude is None: |
| 521 | exclude = list() |
| 522 | |
| 523 | if exclude_glob is None: |
| 524 | exclude_glob = list() |
| 525 | |
| 526 | # Exclude the zip itself |
| 527 | exclude.append(str(archive_path)) |
| 528 | |
| 529 | # Make sure that 'concurrent' is always forbidden. |
| 530 | # https://github.com/Miserlou/Zappa/issues/827 |
| 531 | if "concurrent" not in exclude: |
| 532 | exclude.append("concurrent") |
| 533 | |
| 534 | def splitpath(path): |
| 535 | parts = [] |