Deploying Django with AWS Elastic Beanstalk!
First you need an AWS account, sign up or login if you already have an AWS account.
Go to the Elastic Beanstalk management console to create a new application.
To deploy your Django application, select the Web server environment.
Select the predefined Python configuration. Environment type can be single instance for basic uses. Select load balancing for advanced uses.
Select the source of the application version. Let us use a sample application. You can either upload the code in zip format or you can upload it from the s3 bucket directly.
Next you can change the default environment name and URL if necessary.
You can create additional resources or create a new RDS database if required.
Select the required instance type where you want to deploy your Django application. Select an ssh key for the instance.
Review the information entered and launch the application. The launch could take some time depending upon your application.
A sample application is now deployed successfully.
Create a virtualenv and install the requirements via pip.
To configure your environment enter the required details in the prompt.
Default Region: Choose a region closest to the end user.
Application name: Select the application name, to create a new application eb will use the directory name.
Python version: Ebcli automatically detects that your app is python and asks for a confirmation. Select the appropriate version.
SSH: Select the SSH key required to SSH into your EC2 instance.
Create a file .ebextensions/django.config to define the Django settings module, wsgi path and static directory.You can also add the container commands for the environment in this file.
Command:"source /opt/python/run/venv/bin/activate && python helloworld/manage.py collectstatic --noinput"
Command:"source /opt/python/run/venv/bin/activate && python helloworld/manage.py migrate --noinput"
You can define database credentials as environment variables.
git commit -m "added eb package configuration"
You can define the database environment variables in the configuration settings of the Elastic Beanstalk console.
Now you have successfully updated the code in Elastic Beanstalk environment. Further you can simply update the code by using “eb deploy”. The autoscaling environment will take care of the rest of the deployment process.