So I have an AWS EB environment with and application deployed.
I can't view the applications log output (web.stdout.logs is empty)
You can try by adding the following to your python.config, or by creating new config file, e.g. mylogs.config:
files:
"/opt/elasticbeanstalk/config/private/logtasks/bundle/applogs.conf" :
mode: "000755"
owner: root
group: root
content: |
/opt/python/log/*.log
The /opt/python/log/*.log should be adjusted to your application.
The problem was not that I couldn't see the output, it was always in the /var/log/web.stdout.log file however when I was zipping the file to upload it to the EB environment I was zipping it using the file manager. This caused an issue on upload as the Procfile was being placed beside the application rather than inside of it.
The effect looked like there were no log files, but really the application was just never getting passed to the Procfile.
The solution was
cd path/to/application
zip -r my_application_code.zip .
Now when I upload the zip file to the EB console the Procfile is generated correctly and the applications log files are found in web.stdout.log as normal.
Thanks for your help.
Related
I'm trying to work with Django on Heroku and I'm following this tutorial with its Django template https://devcenter.heroku.com/articles/django-app-configuration
https://devcenter.heroku.com/articles/deploying-python
But when i run 'heroku local web' it always look in the wrong directory. I've tried to move the project
(env) D:\Study\Workbench\heroku-testing\testing\env\codeShareApp>heroku local web
[WARN] No ENV file found
[WARN] ENOENT: no such file or directory, open 'C:\Users\William\Procfile'
[FAIL] No Procfile and no package.json file found in Current Directory - See
run_foreman.js --help
The project directory is as follows
env/
codeShareApp/
.idea/
codeShareApp/
.env
manage.py
Procfile
requirements.txt
runtime
include/
Lib/
Scripts/
tcl/
EDIT:
I tried to make a new project with directory like below, but still got the same error
codeShareApp/
codeShareApp/
env/
.env
manage.py
Procfile
requirements.txt
runtime
I encounter this problem also in a project; I solved this by Making sure that the Procfile is using the correct syntax, and that there are no extra tabs or newlines in the file.
especially whitespcae.
I dont know why, but I tried it on another machine and it works just fine. It seems that it has something to do with heroku cli 6.13 because the error only occurs after it updates from version 5.12 to 6.12
The documentation says:
The file must be placed in the root directory of your application. It will not function if placed in a subdirectory.
Try to do this and it should work. See the docs for more information.
I have an app where I want to run it from aws_wsgi.py instead of application.py, as there are several different entry points depending on where we are hosting it. For this reason, I would like to be able to change the WSGIPath variable to point to the correct location.
This, in an .ebextensions .config file, does not work:
option_settings:
- namespace: "aws:elasticbeanstalk:container:python"
option_name: WSGIPath
value: "/opt/python/current/app/aws_wsgi.py"
The environment attempts to use 'application.py' despite the above lines. No error appears to be emitted. Other parts of that same config file work perfectly, such as packages commands to get the system to install some yum packages. I can confirm the config files are getting uploaded in the logs:
INFO: Creating new application version using project code
WARNING: You have uncommitted changes.
INFO: Getting version label from git with git-describe
Creating application version archive "0_3_0-507-ga36f".
INFO: creating zip using git archive HEAD
INFO: git archive output: .ebextensions/
.ebextensions/01-weave_server_eb.config
.ebextensions/02-weave_server_eb_lxml_dependencies.config
.ebextensions/03-weave_server_eb_nltk_data.config
.ebextensions/04-weave_server_eb_entity_data.config
.ebextensions/05-weave_server_eb_geography_data.config
.gitattributes
.gitignore
...etc.
We run with a saved configuration, i.e. via eb create --cfg Live, and in the dashboard, that configuration shows that WSGIPath is "application.py". But there is nowhere to change that value in the dashboard. It seems like it is a built-in value that overrides the data we send with the above config file.
I tried adding it as an environment variable via the dashboard, but that goes in the aws:elasticbeanstalk:application:environment namespace and does not affect how the application is started up in the first place. (I checked this by using eb config to download the configuration.)
Maybe I could add a section in the file retrieved by eb config, but I heard that doing that will start to override .ebextensions files, and I have several important commands in my .ebextensions files that I need to continue using. (But see the comment below.) It's not clear from the documentation how .ebextensions data translates to and compares with config files used by eb config but the .ebextensions files are well-documented and reasonably convenient so I'd rather not break those if possible!
If I retrieve the configuration on the server via eb config get Live, it contains the following (numerous API keys removed):
EnvironmentConfigurationMetadata:
Description: Includes API keys for live operation
DateModified: '1437734273000'
DateCreated: '1437734273000'
AWSConfigurationTemplateVersion: 1.1.0.0
EnvironmentTier:
Name: WebServer
Type: Standard
SolutionStack: 64bit Amazon Linux 2015.03 v1.4.3 running Python 2.7
OptionSettings:
aws:elb:loadbalancer:
CrossZone: true
aws:elasticbeanstalk:command:
BatchSize: '30'
BatchSizeType: Percentage
aws:autoscaling:launchconfiguration:
IamInstanceProfile: aws-elasticbeanstalk-ec2-role
EC2KeyName: aws-eb
InstanceType: t2.micro
aws:elb:policies:
ConnectionDrainingEnabled: true
aws:autoscaling:updatepolicy:rollingupdate:
RollingUpdateType: Health
RollingUpdateEnabled: true
aws:elasticbeanstalk:application:environment:
DATA_DIR: /opt/python/current/app/data
WSGIPath: /opt/python/current/aws_wsgi.py
aws:elb:healthcheck:
Interval: '30'
(NB. The WSGIPath environment variable there is invalid - but I am unable to remove it from the configuration due to bugs in the AWS Dashboard. It appears to have no effect anyway.)
How do I get AWS to respect my chosen WSGIPath?
I need help from someone who understands linux. I can't push my staticfiles to Heroku (I'm trying to use whitenoise and not Amazon S3 or any CDN). The error is rather simple, when I try to push to heroku I get:
Preparing static assets
Running collectstatic...
Traceback (most recent call last):
OSError: [Errno 30] Read-only file system: '/assets'
So, I can't run collectstatic cause I don't have permissions. If I do sudo git push heroku master I get another error: Permission denied (publickey) And I guess that is cause 'sudo' uses a different SSH key.
I've tried to change permissions to the folder from the file manager and I've also tried from bash:
sudo chmod 777 -R static
static is the parent folder: static/assets.
So... how can I solve this? Any help will be greatly appreciated.
I don't think the problem is pushing content to Heroku, specifically. You're trying to save assets to a root folder on the virtual machine, which your'e not allowed to do.
Traditionally with Heroku, you'd set the static assets directory to something like staticfiles (not /staticfiles or /assets). When Heroku deploys the app to its virtual machines (what it calls "dynos") it works in its own little directory (I think it's /app), so all the directories you specify in your settings.py file are relative to that directory.
Try setting the static files root directory to staticfiles or assets without the slash, and that should work.
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.
I'm running accross an error trying to push my Django project up to Heroku and I was looking to see if anyone had any insight.
! Heroku push rejected, no Cedar-supported app detected
I am guessing it is because of my folder structure in the git repo but I am not sure. My project is setup like this:
/subfolder/djangoproject/
/subfolder/requirements.txt
My Proc file content looks like this:
web: python manage.py runserver 0.0.0.0:$PORT --noreload --settings=djangoproject.settings.heroku
I have my project setting split and they work fine on my local. (In other words I having a setting directory with an init.py in it.)
I tried this:
/Procfile
and this:
/subfolder/Procfile
but neither worked.
Can this folder structure be the culprit? I was under the impression that the requirements.txt was how Heroku found where the project folder was.
Thanks
I wanted to add my solve for the first issue I had and then post the new issue I am having.
The solve I first did was to move the Procfile and requirements.txt files to the root level of the project. The second thing I did was edit the Procfile in so the path to the manage.py script was to the proper location
web: python subfolder/djangoproject/manage.py runserver 0.0.0.0:$PORT --noreload --settings=djangoproject.settings.heroku
I've hit a new error now when trying to run a syncdb. It seems to go through the process but nothing takes. In other words, if I run syncdb once and then run it a second time, it wants to set everything up all over again. Any thoughts on what I may have configures wrong to make the DB not save it's data? Should I use the setting for the DB from the dashboard or keep this line in the Django config:
import dj_database_url
DATABASES['default'] = dj_database_url.config()
Thanks
You need requirements.txt or setup.py in the root of the repo.
See https://github.com/heroku/heroku-buildpack-python/blob/master/bin/detect