Editing
Troubleshooting Deploying a Django Application With Elastic Beanstalk
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Overview == An ongoing list of issues, with solutions as they are found, that I have encountered while deploying a Django web application using Elastic Beanstalk. == Errors installing `awsebcli` on Mac OS for Python 2.7 == '''Use case''' <syntaxhighlight lang="bash"> $pip install awsebcli </syntaxhighlight> <syntaxhighlight lang="text"> [...] Exception: Traceback (most recent call last): File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 209, in main status = self.run(options, args) [...] </syntaxhighlight> '''Cause''' OS X El Capitan ships with `six` 1.4.1 already installed. `awscli` < `botocore` < `python-dateutil` < `six>=1.5`. pip doesn't have permission to System Integrity Protection doesn't it to modify directories.<ref>[https://github.com/pypa/pip/issues/3165 Six issue when installing package] - pypa / pip GitHub Issues</ref> In addition, I suspect I may have installed some components using `sudo pip`. I realize now that it's pretty much always inappropriate to use `sudo` with `pip`. ''' Fix''' ''(Using `sudo` in cases like this may be bad practice, but at this point it was the only way to get it to work with Python 2.7.)''<ref>[http://stackoverflow.com/a/33136494/1399562 “OSError: [Errno 1] Operation not permitted” when installing Scrapy in OSX 10.11 (El Capitan) (System Integrity Protection)] - Stack Overflow</ref> <syntaxhighlight lang="bash"> $ sudo pip install --ignore-installed awsebcli </syntaxhighlight> == "No environment found" error with aws eb cli == '''Use case''' Almost all `eb` commands result in an error the effect of `No Environment found for EnvironmentName = 'name-ev'`. '''Cause''' An EB environment was created, but then not deleted entirely. '''Fix''' Delete the environment through the AWS console, and then delete the `.elasticbeanstalk/` and `.ebextensions/` directories. == Zip file errors while installing a custom Django module == '''Use case''' `pip install path/to/my-custom-package.0.1.zip` results in error: `BadZipFile: File is not a zip file.` '''Cause''' This happened after using wget to retrieve a .zip archive off GitHub. Despite the `.zip` extension, the file type can register as HTML on Linux. '''Fix''' Test the file type: <syntaxhighlight lang="bash"> $ file myzipfile.zip myzipfile.zip: HTML document, UTF-8 Unicode txt, with very long lines </syntaxhighlight> Upload the zip file to the server using `scp`: <syntaxhighlight lang="bash"> `scp -i path/to/namekey_pair.pem path/to/source.zip ec2-user@public_dns.us-west-2.compute.amazonaws.com:path/to/dest.zip` </syntaxhighlight> (Where `namekey_pair.pem` is the actual name of a `.pem` file, and `public_dns` is the actual address of the public dns from the EC2 console.) == `eb deploy` errors where EB environment doesn't match == '''Use case''' Attempting to update `.ebextensions/01-packages.config` to list Git and PostgreSQL as packages to install, then running `eb deploy` to install the packages, the deploy process quits with errors to the effect that the YAML is malformed in the `.config` file. Editing the file makes it evident that the errors are originating in another environment. '''Cause''' Logged into wrong EC2 instance. You can log into an EC2 instance and run `eb init` and `eb create` commands to create new Elastic Beanstalk applications and environments. The new app will spawn a new EC2 instance, ''that is separate from the current EC2 instance''. '''Fix''' It's necessary to `ssh` to the correct EC2 instance to run `eb deploy`. Go back to the AWS EC2 console, find the EC2 instance corresponding to the new EB environment, and `ssh` to its public DNS. == Package version not available on `eb deploy` == '''Use case''' # Run `eb deploy`. # Batch does not complete. # Quits with error to the effect that a package version defined in `requirements.txt` is not available, e.g.: <syntaxhighlight lang="text"> raise DistributionNotFound(req) pkg_resources.DistributionNotFound: requests<2.7,>=2.6.1 </syntaxhighlght> '''Cause ''' `awsebcli` package needs to be upgraded. (Not sure how this is getting set back to an earlier version.) '''Fix''' Upgrade `awsebcli` with `pip install --upgrade awsebcli` == YAML formatting errors on `eb create` == '''Use case''' This is related to the previous troubleshooting case. Run `eb create` and receive error <syntaxhighlight lang="text"> ERROR: The configuration file .ebextensions/02-northrose.config in application version app-dd48-160209_151318 contains invalid YAML or JSON. YAML exception: while scanning for the next token found character '\t' that cannot start any token in "<reader>", line 2, column 1: "aws:elasticbeanstalk:applicati ... ^ , JSON exception: Unexpected character (o) at position 0.. Update the configuration file. </syntaxhighlight> '''Cause''' Not 100% certain about the cause. It's either that changes to the `.config` file needed to be checked in in order to be deployed to the EC2 instance. Or that I had tried recently to launch an environment with the same name, and so the config file in question was still seen in its old state in the previous environment. '''Fix''' 1) Fixed the YAML formatting in the file. Committed the changes, and merged them into the `master` branch. 2) Took some time making the fixes, which possibly gave the AWS Management Console enough time to clear out the previous aborted Elastic Beanstalk environments that shared the environment name. == `manage.py migrate` fails during `eb deploy` == '''Use case ''' Execute `eb deploy` from the command line. No errors reported on the command line (there are probably errors in the logs) but migrate obviously fails and database objects are not available. '''Cause''' Several blog posts related to AWS Django deployment document the following `container_command` (in `.ebextensions/`): <syntaxhighlight lang="yaml"> command: "source /opt/python/run/venv/bin activate && python /opt/python/current/app/migrate.py migrate --noinput" </syntaxhighlight> The problem with that command is the the `RDS_DB_NAME` system environment variable is not available as it is when running the Django application. This causes the process to fall back on local database connection properties which are invalid on the AWS server. '''Fix''' Use `django-admin` instead: <syntaxhighlight lang="yaml"> 01_migrate: command: "django-admin migrate" leader_only: true </syntaxhighligh> == Django project not available after installation == '''Use case''' * Run either `eb create` or `eb deploy` to update an Elastic Beanstalk environment. * Errors occur during installation. * The Django URLs are not available. '''Cause''' Elastic Beanstalk first uploads Django projects to `/opt/python/ondeck/app/` and moved them to `/opt/python/current/app/` after running installation commands. If an error occurs in `requirements.txt` or in one of the `.ebextensions/` scripts, the project files will remain in `ondeck`. '''Fix''' * Search the EB logs (either through the EB Management Console, or with `eb logs`) for the specific error. * Fix the error in either `requirements.txt` or `.ebextensions/`. * Run `eb deploy`. == 404 response for static files == '''Use case''' After deploying to Elastic Beanstalk, stylesheets and other static files are not loaded. URLs such as `/static/grappelli/stylesheets/screen.css` return a 404 response. '''Cause''' `aws:elasticbeanstalk:container:python:staticfiles` setting is incorrect in `.ebextensions/`. '''Fix''' Setting should be `"/static/": "static/"` and not `"/static/": "www/static/"` == Notes == <references /> [[Category:AWS]] [[Category:Elastic Beanstalk]] [[Category:Web Development]] [[Category:Django]]
Summary:
Please note that all contributions to Littledamien Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Littledamien Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information