s_om
s_om

Reputation: 681

Zappa deployment error : GET request yields 502 response code

I am trying to deploy the first zappa example app built 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.

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!")



if name == 'main':
app.run()

Can someone please help me out here?

Upvotes: 17

Views: 14452

Answers (11)

Kartik Gautam
Kartik Gautam

Reputation: 55

I was running a flask app and forgot to include following statement in my app.

if __name__ == '__main__': app.run()

after adding this line it started working fine. šŸ‘

Upvotes: 0

Hamza Hassan
Hamza Hassan

Reputation: 1

I was facing the same issue and I figured out that zappa is installed globally on my system not in the virtual env that I am using.

try installing zappa in virtual env

pip install zappa

Upvotes: 0

Manmohan
Manmohan

Reputation: 440

I was getting same error. check you have installed zappa in your venv. I have installed globally and run in local venv. When i installed zappa it works perfect.

Upvotes: 0

Dinuka Salwathura
Dinuka Salwathura

Reputation: 944

If all of above doesn't work you can solve it by this way.

  • First solve all errors by checking the app log by zappa tail [app name], if you have any

Then, You must provide "app_function" parameter in the zappa_settings.json which should point to your entry function. The app_function should be provided like this if application is Flask __init__.application, so the flask app should be defined as application as follows,

application = Flask(__name__)

app.py should be __init__.py You have to add __init__.py in order to recognize your project folder as a package. So zappa_settings.json have parameter like this,

"app_function": "__init__.application",

Deploy and enjoy!

Upvotes: 2

SarahJessica
SarahJessica

Reputation: 524

I had this same error and after many online searches and trying many, many suggestions, it was actually just a small problem with a code indentation! No problem with Zappa config or pip installations at all.

I notice that in your code sample you have not indented your code at all. I don't know if this is how it copy pasted into StackOverflow or if this is how you unintentionally tried to deploy it. It should be

@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!")


if name == 'main':
    app.run()

Upvotes: 0

Saahil
Saahil

Reputation: 54

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.

Upvotes: 2

HassanSh__3571619
HassanSh__3571619

Reputation: 2077

I faced the same error, and same what happened with ScottieB above, the reason was that I forgot to do the pip install for one package that my .app was using...After I did the pip install locally in the project environment then did the zappa update dev the error gone! and update been completed.

Upvotes: 0

Rishichandra Wawhal
Rishichandra Wawhal

Reputation: 507

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.

Upvotes: 1

zsoobhan
zsoobhan

Reputation: 1524

This github issue seems to have the same symptoms. Downgrading to zappa==0.45.1 solved it for me

Upvotes: 2

Nishank
Nishank

Reputation: 93

I had same problem. After spending couple of hours, from cloudwatch logs I noticed the error of sec certificate. Solved it by running "pip install 'cryptography<2.2'"

Upvotes: 0

Aman Agarwal
Aman Agarwal

Reputation: 643

try installing all the dependencies using pip in the virtual environment where you are using zappa. It worked in my case.

You can also use zappa tail command to see your logs.

Upvotes: 14

Related Questions