Zappa
Zappa copied to clipboard
A GET request to '/' yielded a 502 response code
I am trying to deploy the first example app with Flask-Ask, It looks like everything works good but after the Deploying API statement I get the following error :
Error: Warning! Status check on the deployed lambda failed. A GET request to '/' yielded a 502 response code.
Context
Here is the code I am executing with minor changes to the sample app
from flask import Flask from flask_ask import Ask, question, statement, session import pyodbc
app = Flask(name) ask = Ask(app, '/')
@ask.intent('HelloIntent') def hello(firstname): speech_text = "Hello %s" % firstname return statement(speech_text).simple_card('Hello', speech_text)
@ask.intent('ByeIntent') def bye(): return statement("Ok, goodBye!")
@ask.intent('FarziIntent') def farzi(): return statement("This is just a random fact!")
if name == 'main': app.run()
Python 3.6 is the version I am running
Expected Behavior
Ideally it should give me a link I can use to configure as an endpoint
Actual Behavior
Error: Warning! Status check on the deployed lambda failed. A GET request to '/' yielded a 502 response code.
Your Environment
- Zappa version used: 0.46.1
- Operating System and Python version: Windows 7, Python 3.6
- The output of
pip freeze
:
aniso8601==1.2.0 argcomplete==1.9.3 asn1crypto==0.24.0 awscli==1.15.39 base58==1.0.0 boto3==1.7.39 botocore==1.10.39 certifi==2018.4.16 cffi==1.11.5 cfn-flip==1.0.3 chardet==3.0.4 click==6.7 colorama==0.3.9 cryptography==2.2.2 docutils==0.14 durationpy==0.5 Flask==0.12.1 Flask-Ask==0.9.8 future==0.16.0 hjson==3.0.1 idna==2.7 itsdangerous==0.24 Jinja2==2.10 jmespath==0.9.3 kappa==0.6.0 lambda-packages==0.20.0 MarkupSafe==1.0 placebo==0.8.1 pyasn1==0.4.3 pycparser==2.18 pyOpenSSL==17.0.0 python-dateutil==2.6.1 python-slugify==1.2.4 PyYAML==3.12 requests==2.19.1 rsa==3.4.2 s3transfer==0.1.13 six==1.11.0 toml==0.9.4 tqdm==4.19.1 troposphere==2.3.0 Unidecode==1.0.22 urllib3==1.23 Werkzeug==0.14.1 wsgi-request-logger==0.4.6 zappa==0.46.1
- Link to your project (optional):
- Your
zappa_settings.py
:
{ "testdev": { "app_function": "app.app", "profile_name": null, "project_name": "basic", "runtime": "python3.6", "s3_bucket": "zappa-vb8m8hwzy", "aws_region": "us-east-1", "api_key_required": false, "api_key":"MY_KEY" } }
Could someone please help me out here?
I am facing the same issue. @sourabhsriom by any chance, were you able to solve this issue ?
In my case, it work when adding if statement
that make sure the function being executed is the main function.
If not, the above error has occurred.
How about edit if statement
from if name == 'main':
to if __name__ == '__main__':
?
if __name__ == '__main__':
app.run()
Looks like the issue is with my pyodbc library. I get an error saying :
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 11 for SQL Server' : file not found (0) (SQLDriverConnect)")
Not sure what to do about that, it is working when I run the code on my local
I fixed this issue by doing
pip uninstall zappa
and then
pip install zappa==0.45.1
hope it helps ;)
EDIT: for version 0.45.1, you might also need to apply this patch! :)
https://github.com/Miserlou/Zappa/pull/1479/files
It did not work for me. Now I get the following error:
venv/lib/python3.6/site-packages/botocore/validate.py", line 291, in serialize_to_request raise ParamValidationError(report=report.generate_report()) botocore.exceptions.ParamValidationError: Parameter validation failed: Invalid type for parameter Key, value: None, type: <class 'NoneType'>, valid types: <class 'str'>
First time Zappa user on MacOS. I get the same error. No idea how to proceed.
Edit: zappa tail
hung after dumping some meaningless errors.
But doing a
zappa update dev
zappa tail
Made the latter command go trough and revealed a missing dependency as the reason for the error.
Installing that via pip
made everything work as expected.
Sorry about the n00b noise.
The issues occurs mostly because of the slim_handle option in the zappa_setting.json file. If your deployment zip files after extraction is below 250 MB, remove the option and try.
Otherwise, if you like to use the option. I tried using a Linux machine (From AWS) and it works. No error. The way it works is, the dependencies as a tar.gz file are loaded into S3 and during Lambda function execution, the file is unzipped in the /tmp folder by lambda handler. This mechanism might be broken when deployed through windows or Mac machine.
I do not think it is a OS problem. I have tried to deploy from a local Ubuntu (18 and 16).
@steve-heslouin, is that patch going to be merged into master anytime? :)
For me it was an incompatibility between zappa==0.46.1 and Flask==1.0.2 when I downgraded Flask==0.12.2 all worked as expected. Does Zappa officially support Flask 1.0.2?
There are several cases for which this error occurs (all solutions reported are very different from each other). It would be great to have a list of possible errors to debug. Moreover I recommend the everyone to use the zappa tail
command so that the issues reported are more precise and informative
I will dig into this more tomorrow but wanted to share my logs in case it might help someone.
In my bootstrap code I have this hack and I believe that the new version of Flask no longer has that attribute. This explains why the app works locally but not when deployed. Not sure if anyone else is trying to apply a similar hack on logging but I suspect this might be related. Now why my Zappa sentry error handler didn't catch this, I don't know. And yes, I shouldn't be modifying private variables but I could find no other solution.
if 'SERVERTYPE' in os.environ and os.environ['SERVERTYPE'] == 'AWS Lambda':
logger = logging.getLogger(app.logger_name)
logger.setLevel(logging.DEBUG)
app._logger = logger
[1531844598509] 'Flask' object has no attribute 'logger_name': AttributeError
For me, setting runtime to python2.7 instead of python3.6 was what solved it.
I'm getting this error deploying a Django project on a Mac.
I tried specifying "slim_handler" : "false"
in zappa_settings.json, and running zappa update
, but the problem was the same.
Here's what I get when I run zappa tail
. The name of my Django project is "restfulinj"
[1532564818514] Failed to find library...right filename?
[1532564819773] No module named restfulinj.apps: ImportError
Traceback (most recent call last):
File "/var/task/handler.py", line 567, in lambda_handler
return LambdaHandler.lambda_handler(event, context)
File "/var/task/handler.py", line 237, in lambda_handler
handler = cls()
File "/var/task/handler.py", line 143, in __init__
wsgi_app_function = get_django_wsgi(self.settings.DJANGO_SETTINGS)
File "/var/task/zappa/ext/django_zappa.py", line 20, in get_django_wsgi
return get_wsgi_application()
File "/tmp/ramblings/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup(set_prefix=False)
File "/tmp/ramblings/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/tmp/ramblings/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/tmp/ramblings/django/apps/config.py", line 120, in create
mod = import_module(mod_path)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named restfulinj.apps
I wonder if anyone has gotten a similar error?
Was anyone able to get this running for pyodbc? everytime I deploy I keep getting: No module named 'pyodbc': ModuleNotFoundError
Just putting my particular error out there:
...
... stacktrace
...
File "/var/task/jose/backends/__init__.py", line 3, in <module>
from jose.backends.pycrypto_backend import RSAKey
File "/var/task/jose/backends/pycrypto_backend.py", line 3, in <module>
import Crypto.Hash.SHA256
File "/var/task/Crypto/Hash/SHA256.py", line 55, in <module>
""")
File "/var/task/Crypto/Util/_raw_api.py", line 180, in load_pycryptodome_raw_lib
raise OSError("Cannot load native module '%s'" % name)
OSError: Cannot load native module 'Crypto.Hash._SHA256'
edit: nevermind, fixed by installing pycrypto
Encountering the same issue with spacy
, showing:
[1533876658002] Failed to find library...right filename?
[1533876660063] No module named 'ujson': ModuleNotFoundError
Traceback (most recent call last):
File "/var/task/handler.py", line 567, in lambda_handler
return LambdaHandler.lambda_handler(event, context)
File "/var/task/handler.py", line 237, in lambda_handler
handler = cls()
File "/var/task/handler.py", line 129, in __init__
self.app_module = importlib.import_module(self.settings.APP_MODULE)
File "/var/lang/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "/tmp/classiefier/api/app.py", line 8, in <module>
import spacy
File "/tmp/classiefier/spacy/__init__.py", line 4, in <module>
from .cli.info import info as cli_info
File "/tmp/classiefier/spacy/cli/__init__.py", line 1, in <module>
from .download import download
File "/tmp/classiefier/spacy/cli/download.py", line 11, in <module>
from .link import link
File "/tmp/classiefier/spacy/cli/link.py", line 8, in <module>
from ..compat import symlink_to, path2str
File "/tmp/classiefier/spacy/compat.py", line 5, in <module>
import ujson
ModuleNotFoundError: No module named 'ujson'
ujson
is installed, however.
EDIT: issue might be related to #1499 .ujson
is a library written in C (.so file). I am guessing deployment with Docker is the way to go.
I was facing this error when I gave the modular path to my application as main.py
.
I fixed it by creating an empty file called main.app
just next to main.py
and setting app_function
to main.app
in zappa_settings.json
.
Absolutely no clue what happened underneath, but it worked for me :-D
@wawhal This certainly works if you remove your main.app
file. When you changed the app_function
to main.app
, it made Zappa look in main.py
and use the app
object in there.
As it was called modular path
in the init phase, I got confused. I thought it would be the path to a file (apologies for my bad Python)
It is still not intuitive though. I think a better phrase than modular path
could help.
Has anyone successfully been able to use "pyodbc" library via pip for MS SQL Server within a Flask app deployed to AWS Lambda from Zappa?
I was able to get a successful deployment to AWS Lambda via Zappa with pyodbc installed but when I try to send a GET request to the endpoint which uses the pyodbc library to connect to an RDS instance of MS SQL Server, I get the following error. (Note this works locally).
Error: Warning! Status check on the deployed lambda failed. A GET request to '/' yielded a 502 response code.
I have many flask-apps that work with Postgresql using psycopg2 on Lambda but I think the issue with pyodbc is that there are some "C" dependencies that are not yet support on Lambda or Zappa doesn't have a manylinux wheel for them?
I was facing this error when I gave the modular path to my application as
main.py
.I fixed it by creating an empty file called
main.app
just next tomain.py
and settingapp_function
tomain.app
inzappa_settings.json
.Absolutely no clue what happened underneath, but it worked for me :-D
I solved by renaming my entry file to application_name.py ( assuming you have
"app_function": "application_name.app"
)
Hi everyone, i was fighting with same problem and solution for me was remove cache files, you could use this command: find . -name *.pyc -delete. I reproduce the error using several version of Flask, Zappa and PIP and the error in all cases was related with cache,btw there are more problem using zappa=0.47.1 and pip 19, so if possible use zappa 0.45.1 and pip 9.0.1. I hope that it works for you.
I have experienced the same issue twice today, re-deploying using zappa update
worked the second time if it had failed the first time. I do not know why, just getting started. Maybe du to .pyc files as stated previously.
Regardless, would be nice to fix this, it feels like it could break anytime when deploying for no particular reason and reduces the confidence in the framework.
@sourabhsriom same issue with my deploy, did you find a good general solution?
@ben0it8 I have had this issue pop up in various ways, and the work-around for me has so far always been to deploy with Docker (https://github.com/Miserlou/Zappa#using-zappa-with-docker).
If you are using anaconda than create a new virtual environment "virtualenv lambda" in your project directory and in Scripts/activate. Than deactivate the conda environment with "conda deactivate" and pip install all the packages "pip install numpy pandas sklearn zappa flask".
PS: using "slim_handle"=true also gives this error, so don't use it.
new to python, new to zappa. i guess its only me who did this blunder, i installed zappa outside virtualenv. so when zappa packed, most of dependencies was not there. it got deployed after installing zappa inside virtualenv.
i downgraded to django 2.1 after undeploy, then i deployed it again it worked .. very strange!
Ensure that Zappa and installed packages from pip are all in the virtual environment that you're trying to deploy from.
Like @egyping , I fixed this by downgrading from Django 2.2 to Django 2.1
check this https://stackoverflow.com/a/60014463/7242275
I mistakenly had 2 modules names (both names the same in 2 different route statements) the same when i copied a block of code.
@app.route(/1) def duplicatename ...
@app.route(/2) def duplicatename ...
renaming them properly to unique names fixed this error for me. I hope it helps others.
I am trying to deploy the first example app with Flask-Ask, It looks like everything works good but after the Deploying API statement I get the following error :
Error: Warning! Status check on the deployed lambda failed. A GET request to '/' yielded a 502 response code.
Context
Here is the code I am executing with minor changes to the sample app
from flask import Flask from flask_ask import Ask, question, statement, session import pyodbc
app = Flask(name) ask = Ask(app, '/')
@ask.intent('HelloIntent') def hello(firstname): speech_text = "Hello %s" % firstname return statement(speech_text).simple_card('Hello', speech_text)
@ask.intent('ByeIntent') def bye(): return statement("Ok, goodBye!")
@ask.intent('FarziIntent') def farzi(): return statement("This is just a random fact!")
if name == 'main': app.run()
Python 3.6 is the version I am running
Expected Behavior
Ideally it should give me a link I can use to configure as an endpoint
Actual Behavior
Error: Warning! Status check on the deployed lambda failed. A GET request to '/' yielded a 502 response code.
Your Environment
- Zappa version used: 0.46.1
- Operating System and Python version: Windows 7, Python 3.6
- The output of
pip freeze
:aniso8601==1.2.0 argcomplete==1.9.3 asn1crypto==0.24.0 awscli==1.15.39 base58==1.0.0 boto3==1.7.39 botocore==1.10.39 certifi==2018.4.16 cffi==1.11.5 cfn-flip==1.0.3 chardet==3.0.4 click==6.7 colorama==0.3.9 cryptography==2.2.2 docutils==0.14 durationpy==0.5 Flask==0.12.1 Flask-Ask==0.9.8 future==0.16.0 hjson==3.0.1 idna==2.7 itsdangerous==0.24 Jinja2==2.10 jmespath==0.9.3 kappa==0.6.0 lambda-packages==0.20.0 MarkupSafe==1.0 placebo==0.8.1 pyasn1==0.4.3 pycparser==2.18 pyOpenSSL==17.0.0 python-dateutil==2.6.1 python-slugify==1.2.4 PyYAML==3.12 requests==2.19.1 rsa==3.4.2 s3transfer==0.1.13 six==1.11.0 toml==0.9.4 tqdm==4.19.1 troposphere==2.3.0 Unidecode==1.0.22 urllib3==1.23 Werkzeug==0.14.1 wsgi-request-logger==0.4.6 zappa==0.46.1
- Link to your project (optional):
- Your
zappa_settings.py
:{ "testdev": { "app_function": "app.app", "profile_name": null, "project_name": "basic", "runtime": "python3.6", "s3_bucket": "zappa-vb8m8hwzy", "aws_region": "us-east-1", "api_key_required": false, "api_key":"MY_KEY" } }
Could someone please help me out here?
have you solved the issue?
zappa tail prints the reason of failure. in my case, i was missing to the lib that i was using on code(even though the lib was available local not on virtualenv). fixed this by installing missing plugin/library using pip
I have fixed this issue now When I am hitting Api with postman it asking for authentication token. How to solve this problem?
On Wed, Jun 3, 2020, 23:07 Balamurugan [email protected] wrote:
zappa tail prints the reason of failure. in my case, i was missing to the lib that i was using on code(even though the lib was available local not on virtualenv). fixed this by installing missing plugin/library using pip
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Miserlou/Zappa/issues/1536#issuecomment-638347061, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANESWBOVTCM2AMROBVK6MW3RU2C6ZANCNFSM4FFTGVTA .
It looks like this error is a general case after deployment actually fails for many reasons (listed above in previous comments). I ran today into this for example due to an error in a Python source file.
While I do not think it's really an issue which can be fixed in terms of bug fixing (I think so because I can't currently recognize an error pattern), maybe this error output shall contain an information block with troubleshooting hints i.e. check zappa tail?
Also, probably zappa deploy should check minimal component version requirements.
This was a doozy for me. Indeed, the error was a general case so my fix may not be relevant for most. I had accidentally included a folder unrelated to my flask app in the same directory. This folder contained lots of generated images and so pushed the whole deploy package over the Lambda memory limit. Moving the app to a dedicated directory, with a fresh virtual environment allowed a clean deploy.
I also faced the same issue, but in my case it was a silly mistake which haunted me for 2-3 days. It was a problem with my flask library which was not installed properly. So I resolved the issue by uninstalling flask and re-installing it using
pip uninstall flask
and
pip install flask
Hi All, I am also facing the same issue after when it is trying to deploy API to lambda using zappa, could someone help me here please, below are the details,
Error: Warning! Status check on the deployed lambda failed. A GET request to '/' yielded a 502 response code
OS: Windows 10 zappa 0.54.0 flask 0.12.2 flask-ask 0.9.7
have tried downgrading version of zappa and upgrading flask and other dependencies, but still the issue exists.
zappa settings.py
{ "app_function": "main.app", "expression": "rate(1 day)", "manage_roles": true, "profile_name": "my_profile", "project_name": "my_project", "runtime": "python3.8", "keep_warm": false, "aws_region": "*********" "delete_local_zip": true }
Getting below error in logs, but have added Jinja2=3.0.3 version [which is having markup/escape modules] into the requirement file and could see the same is getting installed.
Zappa tail logs,
[1660653255972] [ERROR] ImportError: cannot import name 'Markup' from 'jinja2' (/var/task/jinja2/init.py)
Traceback (most recent call last):
File "/var/task/newrelic/api/lambda_handler.py", line 122, in nr_lambda_handler_wrapper
result = wrapped(*args, **kwargs)
File "/var/task/voice_handler.py", line 522, in lambda_handler
return LambdaHandler.lambda_handler(event, context)
File "/var/task/voice_handler.py", line 240, in lambda_handler
handler = cls()
File "/var/task/voice_handler.py", line 132, in init
self.app_module = importlib.import_module(self.settings.APP_MODULE)
File "/var/lang/lib/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "