serverless / serverless-python-requirements

⚡️🐍📦 Serverless plugin to bundle Python packages
MIT License
1.11k stars 290 forks source link

Getting error with deployed Serverless Flask app on AWS, [ERROR] Runtime.ImportModuleError: Unable to import module 'wsgi_handler': No module named 'werkzeug' #719

Open shivjetwal opened 2 years ago

shivjetwal commented 2 years ago

Hi I am facing error - [ERROR] Runtime.ImportModuleError: Unable to import module 'wsgi_handler': No module named 'werkzeug'

while deploying serverless application with python3.9.

serverless.yml

service: serverless-service # give the service name

plugins:
  - serverless-python-requirements
  - serverless-wsgi
  - serverless-dotenv-plugin

custom:

  wsgi:

    app: test_wsgi.app  # wsgi file

    packRequirements: false

  pythonRequirements:

    dockerizePip: non-linux

provider:

  name: aws
  runtime: python3.9 # Specify the run time environement
  stage: dev        # For testing use dev
  region: us-west-2 # region specify
  lambdaHashingVersion: 20201221 # Optional, version of hashing algorithm that should be used by the framework

package:
  individually: true
  exclude:
    - ./**
  include:
    - requirements.txt

functions:
  app:
    handler: wsgi_handler.handler # For api gateway we need to use
    timeout: 30   # Default timeout
    events: # If we have any other method type add below
      - http: ANY /
      - http: 'ANY {proxy+}'

requirements.txt

flask==2.1.0
flask-api==3.0.post1
flask-cors===3.0.9
flask-restful==0.3.9
python-dotenv~=0.20.0
#boto3~=1.16.18
#flask-restful
boto3~=1.16.18
requests~=2.28.1
PyJWT==1.7.1
pycryptodomex
werkzeug==2.0.1

can anyone please help in this?

cheiras commented 2 years ago

try Werkzeug==2.0.1

nullwiz commented 1 year ago

I have the exact same issue. Downgrading does not help!

victorstefan13 commented 9 months ago

Also seeing this issue, anyone found a solution?

pgrzesik commented 9 months ago

@victorstefan13 what version of Flask are you using? Some of them requires werkzeug to be installed separately

victorstefan13 commented 9 months ago

Hey @pgrzesik I am using Flask version 2.2.3 but I also have Werkzeug as its own dependency version 2.2.3. I can see the package is in my requirements.txt file which gets generated at the root of my project through poetry. I have also tried older versions, Flask v1.1.4 and Werkzeug v1.0.1 and I was getting the same issue so I am a bit stunned.

victorstefan13 commented 9 months ago

My solution.

alex-morgun commented 2 months ago

Bug Report: Serverless Offline Missing WSGI Files

Title: sls offline fails to create required WSGI files

Severity: High

Environment:

Description: sls offline doesn't create files, which are necessary for WSGI applications.

Steps to Reproduce:

  1. Run sls deploy
  2. Run sls offline
  3. Observe missing files

Expected: sls offline creates required WSGI files Actual: Files are not generated

Workaround: Run sls wsgi install && sls offline