zappa / Zappa

Serverless Python
https://zappa.ws/zappa
MIT License
3.24k stars 363 forks source link

slim_handler option broken #1342

Open MartijnGevaert opened 1 month ago

MartijnGevaert commented 1 month ago

Context

Unable to deploy or update a very simple hello_world Flask application when slim_handler is enabled. This has been a real pain since I have a single dependency that is >250mb, so I can't put it into a separate layer either.

Expected Behavior

slim_handler should not prevent deployment.

Actual Behavior

Following output is shown, I modified the paths for privacy reasons.

3d-platform\test-backend> zappa update dev
Calling update for stage dev..
Downloading and installing dependencies..
INFO: - markupsafe==2.1.5: Using locally cached manylinux wheel
INFO: - pyyaml==6.0.1: Using locally cached manylinux wheel
INFO: - charset-normalizer==3.3.2: Using locally cached manylinux wheel
Packaging project as gzipped tarball.
ERROR: To modify pip, please run the following command:
C:\test-backend\test-backend\.venv\Scripts\python.exe -m pip install --quiet --target C:\test-backend\test-backend\handler_venv\Lib\site-packages zappa==0.59.0 toml==0.10.2 cfn-flip==1.3.0 werkzeug==3.0.3 idna==3.7 troposphere==4.8.1 
boto3==1.34.145 six==1.16.0 click==8.1.7 requests==2.32.3 python-dateutil==2.9.0.post0 urllib3==2.2.2 durationpy==0.7 pip==24.0 PyYAML==6.0.1 MarkupSafe==2.1.5 s3transfer==0.10.2 argcomplete==3.4.0 wheel==0.43.0 tqdm==4.66.4 text-unidecode==1.3 jmespath==1.0.1 charset-normalizer==3.3.2 botocore==1.34.145 placebo==0.9.0 hjson==3.1.0 python-slugify==8.0.4 certifi==2024.7.4 kappa==0.6.0 colorama==0.4.6 setuptools

[notice] A new release of pip is available: 24.0 -> 24.1.2
[notice] To update, run: python.exe -m pip install --upgrade pip    
INFO:command: pip install --quiet --target C:\test-backend\test-backend\handler_venv\Lib\site-packages zappa==0.59.0 toml==0.10.2 cfn-flip==1.3.0 werkzeug==3.0.3 idna==3.7 troposphere==4.8.1 boto3==1.34.145 six==1.16.0 
click==8.1.7 requests==2.32.3 python-dateutil==2.9.0.post0 urllib3==2.2.2 durationpy==0.7 pip==24.0 PyYAML==6.0.1 MarkupSafe==2.1.5 s3transfer==0.10.2 argcomplete==3.4.0 wheel==0.43.0 tqdm==4.66.4 text-unidecode==1.3 jmespath==1.0.1 charset-normalizer==3.3.2 botocore==1.34.145 placebo==0.9.0 hjson==3.1.0 python-slugify==8.0.4 certifi==2024.7.4 kappa==0.6.0 colorama==0.4.6 setuptools
Oh no! An error occurred! :(

==============

Traceback (most recent call last):
  File "C:\test-backend\test-backend\.venv\Lib\site-packages\zappa\cli.py", line 3048, in handle
    sys.exit(cli.handle())
             ^^^^^^^^^^^^
  File "C:\test-backend\test-backend\.venv\Lib\site-packages\zappa\cli.py", line 521, in handle
    self.dispatch_command(self.command, stage)
  File "C:\test-backend\test-backend\.venv\Lib\site-packages\zappa\cli.py", line 574, in dispatch_command
    self.update(
  File "C:\test-backend\test-backend\.venv\Lib\site-packages\zappa\cli.py", line 980, in update
    self.create_package()
  File "C:\test-backend\test-backend\.venv\Lib\site-packages\zappa\cli.py", line 2441, in create_package
    venv=self.zappa.create_handler_venv(use_zappa_release=use_zappa_release),  # type: ignore[attr-defined]
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\test-backend\test-backend\.venv\Lib\site-packages\zappa\core.py", line 494, in create_handler_venv
    if stderror_result.strip():
       ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'strip'

==============

Need help? Found a bug? Let us know! :D
File bug reports on GitHub here: https://github.com/Zappa/Zappa
And join our Slack channel here: https://zappateam.slack.com
Love!,
 ~ Team Zappa!

Possible Fix

Steps to Reproduce

  1. Create a new empty folder
  2. Create a very simple Flask application using the Flask Quickstart guide
    1. create a virtualenv. using py -3 -m venv .venv
    2. activate using .venv\Scripts\activate
    3. run pip install Flask
    4. create a file named main.py containing the code from https://flask.palletsprojects.com/en/3.0.x/quickstart/
    5. run flask --app main run to verify the simple hello world runs locally.
  3. Install zappa by running pip install Zappa within the virtualenv.
  4. Deploy the application using zappa deploy dev. This should work as expected.
  5. Add the line "slim_handler": true
  6. Run zappa update dev, the update should now fail.

Your Environment

Maxiron commented 1 month ago

I keep encountering this same issue when trying to deploy a django project. How did you fix yours if it was fixed

MartijnGevaert commented 1 month ago

@Maxiron I ended up running my application in Docker. https://ianwhitestone.work/zappa-serverless-docker/

Maxiron commented 1 month ago

@Maxiron I ended up running my application in Docker. https://ianwhitestone.work/zappa-serverless-docker/

Thank you

ml3477 commented 2 weeks ago

This issue seems to be on Windows machines only, I can replicate on Windows 11 / Python 3.12. Setting slim_handler to False or using MacOS solves the issue.

Turns out it's been a very long running issue #2145