What can we help you with?

If you are interested in finding out more about how we can help your organization, please provide your details and project requirements. We'll get back to you soon.

3 Easy Steps to deploy Django application on AWS Elastic Beanstalk

Python

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
  • pip
  • virtualenv
  • awsebcli

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:

projects
|— PROJECT
| |— 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
code.

– “env_PROJECT” -> This is a sub-folder inside “PROJECT”. This folder will contain
environment packages

To start the deployment process, please follow below instructions:

– cd projects/PROJECT
– env_PROJECT/Scripts/activate
– 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:

eb --version

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

eb init

This will prompt you with a number of questions to help you configure your environment.

Default region:

13 or us-east-2

Credentials:

(Use AWS credentials listed above i.e. aws_access_key_id and aws_secret_access_key)

Application name:

PROJECT

Python version:

Select appropriate Python version

SSH:

No

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.

eb 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.
Environment Name:

PROJECT-prod

DNS CNAME Prefix:

(Press Enter key)

Deploy application to the Beanstalk

  • Deploying application on Beanstalk is very simple with command:
    – eb deploy