Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package Zappa app dependencies for an alternate virtualenv #1017

Closed
nickovs opened this issue Jul 29, 2021 · 6 comments
Closed

Package Zappa app dependencies for an alternate virtualenv #1017

nickovs opened this issue Jul 29, 2021 · 6 comments
Labels
auto-closed [Bot] Closed, details in comments no-activity [Bot] Closing soon if no new activity

Comments

@nickovs
Copy link

nickovs commented Jul 29, 2021

Context

Currently Zappa packages up pretty much everything in your current virtualenv when you package, deploy or update your application. This often results in the inclusion of a large amount of content that is only used for development and local testing which will never be needed when the code is running on AWS, for instance copies of pylint or black, or libraries that are being used in other projects. While it is possible to exclude a list of individual packages, this is cumbersome when the excluded packages have large or deep dependency trees.

In order to deploy only the necessary package, an alternate virtual environment can be created. Unfortunately this is currently very cumbersome, since it involves the user having to disable their current venv, activate the alternate one, issue the deploy/update command, deactivate the alternate venv and reactivate their development environment.

In the light of this it would be helpful to be able to specify an alternate virtualenv to be packed for use on Lambda, that is distinct from the one used for development and testing in which the Zappa command is executed.

Expected Behavior

The user should be able to provide the path of an alternate virtualenv as a command line argument.

Actual Behavior

Currently to use an alternate virtualenv the user must deactivate their dev venv, activate their production venv, run the deploy/update process, deactivate their production venv and reactivate their dev venv.

Possible Fix

The core Zappa class's create_lambda_zip() method already supports having an alternate venv path being passed to it. Exposing this method's argument via a command line option would allow the user to select their production venv while deploying from their development environment.

@tommie-lie
Copy link

I don't think having a second virtualenv (which has to be maintained separately) is very developer-friendly: poetry won't create and maintain multiple venvs and updating multiple venvs manually is always error-prone (do you remember to update package X in your production environment when you just added it to your dev environment?)

But I found pip-check-reqs which seems like it can alleviate most of the problems described here. black and pylint should not appear in any imports and you can exclude your tests directory, so that you can even exclude packages that are only required for testing (like some pytest packages, mocking libraries, etc.).
Including such a mechanism to auto-detect packages that are really required from the current environment to the lambda bundle would be really nice.

@nickovs
Copy link
Author

nickovs commented Aug 1, 2021

@tommie-lie If Zappa can add a reliable way to auto-detect which packages are really needed and only package those then that would certainly be better than having to maintain a separate environment.

Another alternative would be to add an option to Zappa to supply a requirements.txt file and have it only package the listed requirements. While this would still require manual maintenance, maintaining requirements.txt files is well understood by most developers (and can be automated with tools like pip-check-reqs) and going that route would avoid adding another complex dependency to Zappa.

@dickermoshe
Copy link

Completely agree.
The auto-detecting of needed packages is a feature no-one asked for.
It would be developer friendly to have a requirements.txt andrequirements-dev.txt file.

However being that using Zappa within a Docker container is recommended anyway, you can create a separate virualenv in that Container.
Also see zappadock for easily using a Docker Container for Development with Zappa

@monkut
Copy link
Collaborator

monkut commented Nov 19, 2022

I've experienced this as well, where I've built out a project with testing and development packages which resulted in a package too big for lambda. Resulting in me re-creating the environment without test/dev tools and re-packaging.

Unfortunately the python package management landscape is vast and there is not a single tool used, making a feature like this difficult to implement fully.

In addition, it would be ideal to package in the lambda environment to reduce issues where the wrong package/wheel is used.

So in my opinion it would be best to move to a docker-based packaging approach.
You would still have the issue of how to define the dev vs prodction environments though.

Copy link

github-actions bot commented Apr 3, 2024

Hi there! Unfortunately, this Issue has not seen any activity for at least 90 days. If the Issue is still relevant to the latest version of Zappa, please comment within the next 10 days if you wish to keep it open. Otherwise, it will be automatically closed.

@github-actions github-actions bot added the no-activity [Bot] Closing soon if no new activity label Apr 3, 2024
Copy link

Hi there! Unfortunately, this Issue was automatically closed as it had not seen any activity in at least 100 days. If the Issue is still relevant to the latest version of Zappa, please open a new Issue.

@github-actions github-actions bot added the auto-closed [Bot] Closed, details in comments label Apr 13, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-closed [Bot] Closed, details in comments no-activity [Bot] Closing soon if no new activity
Projects
None yet
Development

No branches or pull requests

4 participants