Error while deploying flask app to Elastic Beanstalk - python

I am trying to deploy a Flask app on AWS Elastic Beanstalk through the console GUI. Following the answer given here Your WSGIPath refers to a file that does not exist,
I have named my main file application.py and have set the WSGIPath (through the Beanstalk console GUI) to application.py. Also, I have named my object application, not app. However, I am still getting this error:
Your WSGIPath refers to a file that does not exist.
Here is my file structure:
Here is the error that shows up
How can I resolve this error?

Related

Issue deploying Django webapp in OVH Hosting

I'm trying to deploy a Django App in OVH Hosting and, after some hard exploration and try-error, I keep getting an issue.
File "/usr/share/passenger/helper-scripts/wsgi-loader.py", line 381, in <module>
handler = RequestHandler(server_socket, sys.stdin, app_module.application)
AttributeError: module 'passenger_wsgi' has no attribute 'application'
OVH/Passenger proccess feedback
Apart from all the files created at startapp by Django and all the code I wrote I added the following file 'passenger_wsgi.py' on the root of the app directory. I used two differents versions:
First:
import MyApp.wsgi
application = MyApp.wsgi.application
Second:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
In the runtime configuration of OVH hosting the application launch script set is 'manage.py'. SECRET_KEY and DJANGO_SETTINGS_MODULE are declared in the environment variables.

ERROR: An app.yaml (or appengine-web.xml) file is required to deploy this directory as an App Engine application

When I try deploying my Python code through Cloud Build to Google App Engine (GAE) I receive the following ERROR message:
ERROR: An app.yaml (or appengine-web.xml) file is required to deploy this directory as an App Engine application
ERROR: (gcloud.app.deploy) [/workspace] could not be identified as a valid source directory or file.
ERROR: build step 0 "gcr.io/google.com/cloudsdktool/cloud-sdk" failed: step exited with non-zero status
Can someone explain what might be causing this error?
A Python app in App Engine is configured using an app.yaml, that contains CPU, memory, network and disk resources, scaling, and other general settings including environment variables. From looking at this error message your app.yaml appears to be missing. You can read more about how to configure your application here: Configuring your App with app.yaml

Error when running "heroku ps:scale web=1": "Couldn't find that process type (web)."

I am attempting to deploy a Heroku Dash app from PyCharm. After running the code to deploy it, I got Heroku error code "H14 - No web dynos running," the solution for which is supposed to be heroku ps:scale web=1. Here is the error I get when attempting to run that line:
Scaling dynos... !
▸ Couldn't find that process type (web).
Others with this problem have been advised to check their procfile. Mine is formatted correctly, with the name "Procfile." Within it is web: gunicorn main:server, where 'main' is the name of the Python file for my app. Any other suggestions about what I could be doing wrong?
The Procfile was created correctly but had not been committed before deployment.

Getting internal server error on Flask App hosted on Azure

I've hosted a flask app on Azure, but there seems to be some problem with linking the WSGIHandler. It is a very simple bug. I can't seem to identify it.
The following is the error I'm getting in my Logs
Error occurred while reading WSGI handler:
Traceback (most recent call last):
File "D:\Python27\Scripts\wfastcgi.py", line 711, in main
env, handler = read_wsgi_handler(response.physical_path)
File "D:\Python27\Scripts\wfastcgi.py", line 568, in read_wsgi_handler
return env, get_wsgi_handler(handler_name)
File "D:\Python27\Scripts\wfastcgi.py", line 551, in get_wsgi_handler
raise ValueError('"%s" could not be imported' % handler_name)
ValueError: "App" could not be imported
StdOut:
StdErr:
ErrorCode Access is denied.
(0x5)
Here is my folder structure
myapplication
-- App
-- __init__.py
The contents of __init__.py is
from flask import Flask
# initialize the flask app
app = Flask(__name__)
print "init"
#app.route('/')
def hello():
return "hello world";
if __name__ == "__main__":
app.run()
I've configured the following App Settings in Azure Web App
PYTHONPATH = D:\home\site\wwwroot
WSGI_HANDLER = App.app
Per my understanding, your deployment is incompleteness, as Azure uses IIS to host python web sites on Web Apps Services, which needs a web.config to configure hander mapping and URL rewrite rules and some other settings.
To create and deploy a flask project on Azure Web Apps , we can generally follow the steps below:
1, On Azure manage portal, click NEW => COMPUTE => WEB APP =>FROM GALLERY at the bottom navigation, on the ADD WEB APP dialog, select Flask, name the site on the next dialog page. Now we have created a flask web site project.
We can type the endpoint on the browser to check the website, http://<your_site_name>.azurewebsite.net
2,On the web apps list, click the name we created above to get into the configuration page, click DASHBOARD, at the quick glance column, click Set up deployment from source control ,select Local Git repository. Now there is an additional tab named DEPLOYMENT beside the DASHBOARD tab. And in the DEPLOYMENT page there are steps of how to deploy your site by git. We can clone the project to local by the GIT URL provided on this page.
We can get more on this official article

How to deploy structured Flask app on AWS elastic beanstalk

After successfully deploying a test app using the steps outlined here:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Python_flask.html
I tried to deploy my actual flask application which has the following structure:
myApp/
runServer.py
requirements.txt
myApp/
__init__.py
helpers.py
clean.sh
static/
myApp.css
handlers/
__init__.py
views.py
templates/
layout.html
viewOne.html
viewTwo.html
Where views.py contains my url mappings.
I have tried initializing the eb instance in the root directory as well as within the myApp module and git aws.push but I get the following error on the AWS dashboard:
ERROR Your WSGIPath refers to a file that does not exist. and the application does not work (404 for any path).
How can I deploy the above Flask application to elastic beanstalk?
I encountered a similar problem deploying a Flask application to EB, with a similar directory structure, and had to do 2 things:
Update my manage.py to create an object of name application, not app
import os
from application import create_app, db
from flask.ext.script import Manager, Shell
application = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(application)
Create .ebextensions/myapp.config, and define the following block to point to manage.py
option_settings:
"aws:elasticbeanstalk:container:python":
WSGIPath: manage.py
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "application/static/"
This let Elastic Beanstalk find the application callable correctly.
This is described briefly at the official docs, and is described in more detail in this blog post
EDIT - see project structure below
ProjectRoot
.ebextensions
application.config
application
main
forms.py
views.py
static
templates
tests
manage.py
requirements.txt
config.py
etc, etc
Add the following to .ebextensions/<env-name>.config:
option_settings:
"aws:elasticbeanstalk:container:python":
WSGIPath: myApp/handlers/views.py
Update:
If you don't have .ebextensions directory, please create one for the project. You can find more information of what can be done regarding the container configuration in Customizing and Configuring AWS Elastic Beanstalk Environments guide.
Your WSGIPath refers to a file that does not exist.
This error appears because Beanstalk, by default, looks for application.py. Check at Beanstalk web UI, Configuration > Software Configuration, WSGIPath is mapped to application.py
Update the WSGIPath as shown in the previous replies or rename to application.py file.
As of awsebcli 3.0, you can actually edit your configuration settings to represent your WSGI path via eb config. The config command will then pull (and open it in your default command line text editor, i.e nano) an editable config based on your current configuration settings. You'll then search for WSGI and update it's path that way. After saving the file and exiting, your WSGI path will be updated automatically.
WSGI configuration was painful for me. I did changed WSCI settings using eb config command but it did not work. Below you can fix this in 5 easy steps.
1- Moved app.py function to the root of the directory (where I runned eb init command.
2- Also renamed app.py as application.py and in that initilized application as application = Flask(__name__) not app = Flask(__name__)
3- eb deploy did not worked after this (in the same project) I tried to fix config by using eb config but it was too hairy to sort it out. Delete all .extensions, .gitignore etc from your project.
4- re initialize your project on EB with eb init and follow the prompts. when deployment is done, eb open would launch your webapp (hopefully!)
When I encountered this problem it was because I was using the GUI to upload a zip of my project files. Initially I was zipping the project level directory and uploading that zip to EB.
Then I switched to simply uploading a zip of the project files themselves-ie select all files and send those to a zip-and then the GUI upload utility was able to find my application.py file without a problem because the application.py file was not in a subfolder.
Well, In my case I followed the entire process and conventions but was still getting 404. The problem was my virtual environment. I was ignoring all environment config related folders/files in my .gitignore but not in .ebignore. After creating .ebignore and ignoring all the folders/files which were not related to project code, fixed the issue.

Categories