3 Easy Steps to deploy Django application on AWS Elastic BeanstalkPython
Elastic Beanstalk (EB) is a Platform as a Service (PaaS) that streamlines the setup, deployment, and maintenance of your app on Amazon AWS. It’s a managed service, coupling the server (EC2), database (RDS), and your static files (S3). This blog walks through the deployment of a default Django website to an Elastic Beanstalk environment running Python 2.x or 3.x.
This blog uses the EB CLI as a deployment mechanism, but you can also use the AWS Management Console to deploy a ZIP file containing your project’s contents for your web application development. The EB CLI is an interactive command line interface written in Python that uses the Python SDK for AWS (boto).
To follow this tutorial, you should have the following python packages:
- Python 2.x or 3.x
1. Getting Started
You should have PROJECT application development with Django already installed and working in development environment on your machine.
If not please follow instruction to setup.
Your project folder should look like this:
| |— PROJECT
| |— env_PROJECT
– “PROJECT” -> This is a sub-folder inside projects. This folder will contain environment
packages and application code.
– “PROJECT” -> This is a sub-folder inside “PROJECT”. This folder will contain application
– “env_PROJECT” -> This is a sub-folder inside “PROJECT”. This folder will contain
To start the deployment process, please follow below instructions:
– cd projects/PROJECT
– cd PROJECT
Above command will activate the environment for the PROJECT project and will get you ready for the deployment.
2. CLI For AWS Elastic Beanstalk
To work with Amazon Elastic Beanstalk, we have to use “awsebcli” package. As of this writing the latest version of is 3.11.0 and the recommended way to install it is with pip.
pip install awsebcli
Run below command to make sure it’s installed and working:
By running above command it will display version number like 3.1
To actually start using Elastic Beanstalk you will need an account with AWS. We already have aws account details as below:
aws_access_key_id = xxxxxxxxxxxxxxxxxxxx
aws_secret_access_key = xxxx26/xxxxw3+qwHjy/P/xxxx8a6Nxxxxx
Keep it handy
3. Configure EB – Initialize your Application
With the AWS Elastic beanstalk CLI working, the first thing we have to do is create a Beanstalk
environment to host the application. Run below command from the project directory
This will prompt you with a number of questions to help you configure your environment.
13 or us-east-2
(Use AWS credentials listed above i.e. aws_access_key_id and aws_secret_access_key)
Select appropriate Python version
Once eb init is finished, you will see a new hidden folder called .elasticbeanstalk in your project directory.
Inside that directory is a config.yml file which is a configuration file that is used to define certain parameters for your Beanstalk application.
Your config.yml file should look like this.
branch-defaults: master: environment: PROJECT-prod environment-defaults: PROJECT-env: branch: null repository: null global: application_name: PROJECT default_ec2_keyname: null default_platform: Python 3.4 default_region: us-east-2 include_git_submodules: true instance_profile: null platform_name: null platform_version: null profile: eb-cli sc: git workspace_type: Application
If not, please copy and paste above code and change config.yml file.
Run this command to check Beanstalk console.
Configure Elastic Bean – create an environment
- Don’t run any command from this section as the environment is already created.
- To create your environment, run below command in Beanstalk console
– eb create
- Just like eb init this command will prompt you with a series of questions.
DNS CNAME Prefix:
(Press Enter key)
Deploy application to the Beanstalk
- Deploying application on Beanstalk is very simple with command:
– eb deploy