Invalid requirements.txt on deploying django app to aws beanstalk - python

I have been deploying my app without any issues to the beanstalk environment until my latest commit.
Now I get this
Time Type Details
2013-09-01 10:19:12 UTC+0800 ERROR Failed to deploy application.
2013-09-01 10:19:11 UTC+0800 ERROR Responses from [i-50f40d06] were received, but the commands failed.
2013-09-01 10:19:11 UTC+0800 ERROR Your requirements.txt is invalid. Snapshot your logs for details.
2013-09-01 10:19:11 UTC+0800 ERROR [Instance: i-50f40d06 Module: AWSEBAutoScalingGroup ConfigSet: Hook-PreAppDeploy] Failed on instance with return code: 1 Output: Error occurred during build: Command hooks failed .
The snapshot logs say this:
2013-09-01 02:19:08,852 [INFO] (9941 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Output from script: New python executable in /opt/python/run/venv/bin/python2.6
Not overwriting existing python script /opt/python/run/venv/bin/python (you must use /opt/python/run/venv/bin/python2.6)
Installing distribute..................................................................................................................................................................................................done.
Installing pip................done.
2013-09-01 02:19:08,564 ERROR Error installing dependencies: Command '/opt/python/run/venv/bin/pip install --use-mirrors -r /opt/python/ondeck/app/requirements.txt' returned non-zero exit status -9
Traceback (most recent call last):
File "/opt/elasticbeanstalk/hooks/appdeploy/pre/03deploy.py", line 31, in main
install_dependencies()
File "/opt/elasticbeanstalk/hooks/appdeploy/pre/03deploy.py", line 25, in install_dependencies
shell=True)
File "/usr/lib/python2.6/subprocess.py", line 502, in check_call
raise CalledProcessError(retcode, cmd)
CalledProcessError: Command '/opt/python/run/venv/bin/pip install --use-mirrors -r /opt/python/ondeck/app/requirements.txt' returned non-zero exit status -9
2013-09-01 02:19:08,853 [ERROR] (9941 MainThread) [directoryHooksExecutor.py-34] [root directoryHooksExecutor error] Script failed with returncode 1
2
My requirements.txt is the same as before. I tried removing everything in the requirements.txt as well but I get the same error again which makes me think the problem was before requirements.txt was run.
I don't know the order in which things are deployed. ANyway, here is my config file:
packages:
yum:
libjpeg-devel: '6b'
zlib-devel: []
freetype-devel: []
container_commands:
01_install_mysqldb:
command: "pip install distribute==0.6.28; pip install mysql-python;"
02_syncdb:
command: "python manage.py syncdb --noinput"
leader_only: true
03_createadmin:
command: "python scripts/createadmin.py"
leader_only: true
04_collectstatic:
command: "python manage.py collectstatic --noinput"
05_migrate_wizards:
command: "python manage.py migrate wizards --noinput"
leader_only: true
06_migrate_facebook:
command: "python manage.py migrate facebook --noinput"
leader_only: true
07_migrate_socialaccount:
command: "python manage.py migrate socialaccount 0011 --noinput"
leader_only: true
08_migrate_missions:
command: "python manage.py migrate missions --noinput"
leader_only: true
09_migrate_mailchimp:
command: "python manage.py migrate mailchimp --noinput"
leader_only: true
10_migrate_actstream:
command: "python manage.py migrate actstream --noinput"
leader_only: true
option_settings:
- namespace: aws:elasticbeanstalk:container:python
option_name: WSGIPath
value: ideatory/wsgi.py
- namespace: aws:elasticbeanstalk:container:python:staticfiles
option_name: /static/
value: static/
- option_name: DJANGO_SETTINGS_MODULE
value: ideatory.settings

I had the exact same problem. The only thing that worked for me was (automatically) rebuilding my entire environment. You can do that in the AWS console. Go to your environment and click Actions > Rebuild Environment. This will take some time, afterwards it will automatically relaunch your app without this error.
Update:
The problem keeps returning so now and then. I figured out that something is going wrong when pip compiles psycopg, which is needed for postgreSQL support. Haven't found a real solution yet.

I was able to make this work by adding postgresql93-devel and postgresql93 to my .ebextensions
as described in Customizing the Software on EC2 Instances Running Linux
This is working for 64bit Amazon Linux 2014.09 v1.0.9 running Python 2.7
in .ebextensions/01_pre_deps.config:
packages:
yum:
gcc-c++: []
make: []
openssl-devel: []
git: []
python-devel: []
python27-devel: []
ruby-devel: []
postgresql93: []
postgresql93-devel: []
# nginx: []
rubygems:
bundler: '1.7.3'
compass-core: '1.1.0.alpha.3'
neat-compass: '1.6.0'

Have you made sure mysql-devel package is installed? It doesn't seem to be included in the yum section of your config file.

Although a different scenario than described by the OP, it may be of use to someone:
We got the same ERROR Your requirements.txt is invalid. Snapshot your logs for details. message while trying to deploy a minimal test app to a newly created t1.micro instance on Elastic Beanstalk.
The test app consisted of the basic AWS Python sample app (from here), to which we added the .ebextensions/software.config and requirements.txt from our production environment. The sole purpose was to test these two files in deployment.
Closer inspection of the logs uncovered a MemoryError during pip install. After upgrading to a t2.small instance, the deployment succeeded without issue.

For whatever reason AWS wouldn't install postgresql-devel packets from my .extensions/01_packets.config as yolk suggested. So instead I had to add
container_commands:
01_addPostgreSQLPacket:
command: 'yum install postgresql95-devel'
leader_only: true
to my 02_django.config. After That it worked just fine.

Related

How to resolve the error "an error occured: no such file or directory for a Django/Python3 app"

I followed this tutorial: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html
I was able to stand up my Django project on my local MacBook pro, but when deploying to AWS EB, it failed, logs below:
2021/02/03 23:50:45.548154 [INFO] Executing instruction: StageApplication
2021/02/03 23:50:45.807282 [INFO] extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/
2021/02/03 23:50:45.807307 [INFO] Running command /bin/sh -c /usr/bin/unzip -q -o /opt/elasticbeanstalk/deployment/app_source_bundle -d /var/app/staging/
2021/02/03 23:50:46.552599 [INFO] finished extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/ successfully
2021/02/03 23:50:46.553257 [ERROR] An error occurred during execution of command [app-deploy] - [StageApplication]. Stop running the command. Error: chown /var/app/staging/bin/python: no such file or directory
2021/02/03 23:50:46.553265 [INFO] Executing cleanup logic
2021/02/03 23:50:46.553350 [INFO] CommandService Response: {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"Engine execution has encountered an error.","returncode":1,"events":[{"msg":"Instance deployment failed. For details, see 'eb-engine.log'.","timestamp":1612396246,"severity":"ERROR"}]}]}
My research led me to this post: AWS Elastic Beanstalk chown PythonPath error, but when I tried the suggested command: git rm -r --cached venv in my project directory, it returned:
fatal: pathspec 'venv' did not match any files
If you type eb logs into the command line and look for the eb-engine.log section you might be able to get more details.
Also maybe verify that you set up you eb cli correctly. Here is the link to setting it up, look at section 2.3 and make sure you have all the requirements installed appropriately.
https://github.com/aws/aws-elastic-beanstalk-cli-setup
Finally double check your python version(s) you have installed. the tutorial is calling python-3.6 but you may not have that version installed.

Elastic Beanstalk: /bin/sh: /opt/python/run/venv/bin/activate: No such file or directory

Trying to deploy a django app which uses channels following this https://medium.com/#elspanishgeek/how-to-deploy-django-channels-2-x-on-aws-elastic-beanstalk-8621771d4ff0
These are my config files:
01_env.config
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: "dashboard/wsgi.py"
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: "dashboard.settings"
PYTHONPATH: /opt/python/current/app/dashboard:$PYTHONPATH
aws:elbv2:listener:80:
DefaultProcess: http
ListenerEnabled: 'true'
Protocol: HTTP
Rules: ws
aws:elbv2:listenerrule:ws:
PathPatterns: /websockets/*
Process: websocket
Priority: 1
aws:elasticbeanstalk:environment:process:http:
Port: '80'
Protocol: HTTP
aws:elasticbeanstalk:environment:process:websocket:
Port: '5000'
Protocol: HTTP
02_setup.config
container_commands:
00_pip_upgrade:
command: "source /opt/python/run/venv/bin/activate && pip install --upgrade pip"
ignoreErrors: false
01_migrate:
command: "django-admin.py migrate"
leader_only: true
02_collectstatic:
command: "django-admin.py collectstatic --noinput"
03_wsgipass:
command: 'echo "WSGIPassAuthorization On" >> ../wsgi.conf'
When I run eb create django-env it fails with
Command failed on instance. An unexpected error has occurred [ErrorCode: 0000000001].
and in the logs, I found that the reason is:
2020-06-17 16:36:41,880 P4189 [INFO] Command 00_pip_upgrade
2020-06-17 16:36:41,883 P4189 [INFO] -----------------------Command Output-----------------------
2020-06-17 16:36:41,883 P4189 [INFO] /bin/sh: /opt/python/run/venv/bin/activate: No such file or directory
So even though I'm following the guide, the directory seems to not exist. I'm also not being able to SSH into the EC2 instance to check this. Has the python venv directory in Amazon Linux 2 changed?
This does not work because you are using Amazon Linux 2, while the tutorial you are following is using Amazon Linux 1.
To use Amazon Linux 1 when you create your Python environment, please choose:
Python 3.6 running on 64bit Amazon Linux
Please note that there are massive differences between AL2 and AL1, and most tutorials involving AL1 will not work in AL2.

Not able to deploy the django app on elastic beanstalk

When trying to deploy my django app using eb deploy I am getting the following error. It is totally unseful and does not let me knwo what to do. Please help.
I am following the tutorial here : http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html
sh-3.2# eb deploy
Creating application version archive "app-ca0a-151123_205119".
Uploading learningsite/app-ca0a-151123_205119.zip to S3. This may take a while.
Upload Complete.
INFO: Environment update is starting.
INFO: Deploying new version to instance(s).
ERROR: Your requirements.txt is invalid. Snapshot your logs for details.
ERROR: [Instance: i-18ee63c1] Command failed on instance. Return code: 1 Output: (TRUNCATED)...)
File "/usr/lib64/python2.7/subprocess.py", line 540, in check_call
raise CalledProcessError(retcode, cmd)
CalledProcessError: Command '/opt/python/run/venv/bin/pip install -r /opt/python/ondeck/app/requirements.txt' returned non-zero exit status 1.
Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/03deploy.py failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
ERROR: Unsuccessful command execution on instance id(s) 'i-18ee63c1'. Aborting the operation.
ERROR: Failed to deploy application.
ERROR: Failed to deploy application.
sh-3.2#
welcome to EB! You'll get plenty of hard to decrypt error messages.
The important line here is ERROR: Your requirements.txt is invalid. Snapshot your logs for details. There is something wrong with your requirements.txt file and EB is not able to install.
Locally if you run pip install -r requirements.txt you might be able to see the error.

"./postinstall" failed with return code [Timeout]

when i run 'dotcloud push traing'... running postinstall script take a long time and get error below.
I created a new account.
cd to project and run command: 'dotcloud create training' and 'dotcloud push training' but nothing change.
anyone can help me?plz
Running postinstall script...
ERROR: deployment aborted due to unexpected command result: "./postinstall" failed with return code [Timeout]
postinstall
#!/bin/sh
#python createdb.py
python training/manage.py syncdb --noinput
python mkadmin.py
mkdir -p /home/dotcloud/data/media /home/dotcloud/volatile/static
python training/manage.py collectstatic --noinput
requirements.txt
Django==1.4
PIL==1.1.7
Try this as your postinstall. It may help with locating the error (expanding on Ken's advice):
#!/bin/bash
# set -e makes the script exit on the first error
set -e
# set -x will add debug trace information to all of your commands
set -x
echo "$0 starting"
#python createdb.py
python training/manage.py syncdb --noinput
python mkadmin.py
mkdir -p /home/dotcloud/data/media /home/dotcloud/volatile/static
python training/manage.py collectstatic --noinput
echo "$0 complete"
More debugging info available at http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html
Any error messages like "./postinstall failed with return code" means that there is a problem with your postinstall script.
In order to debug postinstall executions easily on dotCloud, you can do the following:
Let's assume that your app is "ramen" and your service is "www".
$ dotcloud -A ramen run www
> ~/current/postinstall
It'll re-execute the postinstall but from your session this time, so you'll be able to easily update the postinstall code and re-run it without having to push again and again.
Once you found the root cause, fix it locally and repush your application.

Fabric - sudo -u

I'm using fabric to launch a command on a remote server.
I'd like to launch this command as a different user (neither the one connected nor root).
def colstat():
run('python manage.py collectstatic --noinput')
Trying
def colstat():
sudo('-u www-data python manage.py collectstatic --noinput')
Oviously this won't work because -u will be considered as a command and not an option of sudo
out: /bin/bash: -u : command not found
(www-data is the user which should run the command)
How can I use www-data to run my command from Fabric ?
Judging from the documentation:
sudo('python manage.py collectstatic --noinput', user='www-data')

Categories

Resources