Don't already have an account? Create an account.
By creating an Ordinary Coders account, you agree to Ordinary Coders' Terms and Conditions.
If you already have an account, login instead.
Amazon Web Services provides users two options for Elastic Beanstalk (EB) deployment:
(1) the AWS Elastic Beanstalk Command Line Interface (EB CLI)
(2) the AWS Elastic Beanstalk console
This Django + AWS Elastic Beanstalk tutorial will demonstrate how to deploy a Django web app within the AWS EB console provided on the AWS site.
Create a free tier AWS account before following the instructions listed below.
Django AWS Elastic Beanstalk
Deploying your Django project using the AWS Elastic Beanstalk console requires certain configuration settings and files to be added to your project before upload. This includes a requirements.txt file, an .ebextensions file, and a django.config file.
Elastic Beanstalk requirements.txt
(env)User-Macbook:mysite user$ pip freeze > requirements.txt
Windows Command Prompt
(env) C:\Users\Owner\desktop\code\env\mysite> pip freeze > requirements.txt
Start with your local server running your completed app. Ctrl + C and stop running the server. You should still be in the mysite folder with your virtual environment activated.
Then save all of your installed apps in a requirements.txt file created by the command pip freeze > requirements.txt. This will allow Elastic Beanstalk to use all of the packages installed locally.
pip freeze > requirements.txt
View requirements.txt file
env > mysite > requirements.txt
Open the requirements.txt file in your code editor. Only edit the file if there is a package listed with a version 0.0.0. Delete this version 0.0.0 package, if listed, to prevent errors upon deployment. Save the changes made to the file.
Create an .ebextensions folder
(env)User-Macbook:mysite user$ mkdir .ebextensions
(env) C:\Users\Owner\desktop\code\env\mysite> mkdir .ebextensions
In the CLI, run the command mkdir .ebextensions to create an .ebextensions folder. This folder will hold the Django + AWS Elastic Beanstalk settings.
Create a django.config file
env > mysite > .ebextensions > (New File) django.config
Open the new folder .ebextensions in your code editor and create a new file named django.config.
Place the above ebextensions option_settings configurations in the file to allow AWS EB to find the wsgi.py file and properly forward requests in production.
If your project is not called mysite, change it to the correct name.
Deploy Django to AWS Elastic Beanstalk Console
With the proper configurations added, we can move on to zipping your root directory and deploying it to the AWS Elastic Beanstalk console.
Zip your Django project
Next, locate your Django project in Windows File Explorer or Mac Finder and zip all of the files located within the project directory.
Do not zip the project folder itself.
The items being zipped should include the .ebextensions, main, and mysite folders along with the database, manage.py, and requirements.txt files.
AWS Elastic Beanstalk Upload Zip
Login to your AWS account and open the Elastic Beanstalk console. Click the "Create Application" button on the right side of the screen.
Then name your application in the Application Information section. You can keep the Application tags section blank.
Select "Python" for your platform and the rest of the Platform section will auto-fill.
Finally, under Application code select "Upload your code". A new section will appear called Source code origin where you need to select "Local file" and upload the folder zipped in the previous step.
Once the folder is done uploading, click "Create Application" at the bottom of the page to continue. AWS EB will then begin launching your project.
Open your project in the browser
When your project is done deploying, you will be brought to the environment dashboard. To view the deployed project, click the Elastic Beanstalk domain listed at the top of the page.
If your environment is producing WARN events, make sure you have followed all of the previous steps and configured the files correctly.
Handling more specific errors
ERROR: Your WSGIpath refers to a file that does not exist
If you are getting "ERROR Your WSGIPath refers to a file that does not exist." :
"ERROR Your WSGIPath refers to a file that does not exist."
Check the django.config file and make sure it has the right code and formatting. Save the changes to the file, re-zip the project, then deploy again.
If you are still getting "ERROR Your WSGIPath refers to a file that does not exist." :
If this error is still occurring after you redeploy, go to the environment page and select Configuration on the side menu.
Under the Software category, click "Edit" and find the WSGIPath.
Change the path to mysite/wsgi.py then save the changes and wait for the environment to update.
Add your project's name in place of mysite if your project's root directory is not named mysite.
ERROR: .ebextensions not working
If your .ebextensions folder is not working correctly, check that it is added to the root directory of your project.
This is the folder created by the command django-admin startproject. It is also the folder that contains the database, manage.py, and requirements.txt.
If you are getting a 500 error and everything seems to be configured properly, check that the requirements.txt file does not have a package listed with a version 0.0.0.
This package with a 0.0.0 version number causes the requirements.txt file to not be read correctly. Deleting the package and redeploying should solve the issue.
Django Stripe SaaS Boilerplate
Django and Stripe integrated together to create a SaaS boilerplate. Django authentication, static files, messages, forms, templates, URLs, …
Django Powered Blog for Affiliate Marketing
A Django powered blog and product showcase for affiliate marketing from Building a Django Web App course. Pre-built Django …
Follow us @ordinarycoders
Post a Comment
Join the community
April 25, 2020, 2:43 p.m.
July 14, 2021, 11:32 a.m.
July 5, 2021, 2:47 p.m.
June 14, 2021, 5:20 p.m.
April 14, 2021, 10:03 a.m.
March 29, 2021, 7:30 p.m.