Django App Prerequisites for AWS Elastic Beanstalk: Difference between revisions

From Littledamien Wiki
Jump to navigation Jump to search
mNo edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:Django]] [[Category:AWS]] [[Category:Web Development]]
== Create a virtual Python environment for the Django project ==
== Install Python ==
 
Check for python and pip, and their versions:
 
<syntaxhighlight lang="bash">
$ python --verison
$ pip --version
</syntaxhighlight>
 
=== Python 3.x ===
 
Python 3.x is often invoked as `python3`.
 
<syntaxhighlight lang="bash">
$ python3 --verison
</syntaxhighlight>
 
If Python 3 is not installed:<ref>[http://stackoverflow.com/questions/27669927/how-do-i-install-python3-on-an-aws-ec2-instance How do I install python3 on an AWS instace] (Stackoverflow)</ref>
 
<syntaxhighlight lang="bash">
$ sudo yum list | grep python3
$ sudo yum install python34 # or relevant version
</syntaxhighlight>
 
== Create a virtual Python environment for the EC2 instance ==


Install `virtualenv` if needed:
Install `virtualenv` if needed:
Line 36: Line 11:


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
$ virtualenv -p python3.4 ./.venv
$ virtualenv -p python3.4 /path/to/project_venv
</syntaxhighlight>
</syntaxhighlight>


Where `py34_nrose_env` is a name that makes sense for the app's virtual environment.
Where `/path/to/project_env` is a path unique to the project.


Start the virtual environment:
Start the virtual environment:


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
$ . ./.venv/bin/activate
$ . /path/to/project_venv/bin/activate
</syntaxhighlight>
</syntaxhighlight>


Line 59: Line 34:
</syntaxhighlight>
</syntaxhighlight>


== Install Django <ref>[http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html#python-django-install Install Django] (Deploying a Django Application - AWS Elastic Beanstalk)</ref> ==
== Create a Django application locally ==


(Make sure to use the virtual Python 3 environment.)
* Install all prerequisites necessary for the Django app, e.g. Python, pip, Django, etc.
 
* See [[Working With Django Projects, The Basics]]
<syntaxhighlight lang="bash">
* Run and test the Django application locally, e.g. with `python manage.py runserver`.
$ pip install django
</syntaxhighlight>
 
Confirm the installation with
 
<syntaxhighlight lang="bash">
$ pip freeze | grep -i django
Django==1.9.2
</syntaxhighlight>
 
[[Deploying a Django app on AWS|Install the Django project]] [[Defining Django App Dependencies|and its dependencies]].


== Install AWS Elastic Beanstalk CLI <ref> [http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-common-steps.html#python-common-installing-ebcli Installing the AWS Elastic Beanstalk CLI] (AWS documentation)</ref> ==
== Install AWS Elastic Beanstalk CLI <ref> [http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-common-steps.html#python-common-installing-ebcli Installing the AWS Elastic Beanstalk CLI] (AWS documentation)</ref> ==


It's necessary to give the EC2 IAM role permission to assign AWS Elastic Beanstalk roles.
Install the AWS Elastic Beanstalk cli:


''N.B. It would probably be better to have a dedicated IAM user account to perform these actions, and assign this policy to a group that the user account would then be included in.
''N.B. See [[Troubleshooting_Deploying_a_Django_Application_With_Elastic_Beanstalk#Errors_installing_awsebcli_on_Mac_OS_for_Python_2.7|the Troubleshooting article]] for issues installing `awsebcli` on Mac OS X.''
 
'''[https://console.aws.amazon.com/iam/home AWS IAM Management Console]''' > '''Roles''' > `nrosedevs_ec2_iam_role` > '''Permissions''' tab > '''Attach Policiy''' button > select `AWSElasticBeanstalkFullAccess`
 
 
<p class="alert alert-warning">I couldn't get the following command to work until I switched to the Python 3.4 virtual environment.</p>


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Line 93: Line 52:
Confirm the installation with `eb --version`
Confirm the installation with `eb --version`


Create an Elastic Beanstalk application in the project directory:
At this point the directory is ready to have an Elastic Beanstalk application created with `eb init`. See [[Deploying a Django app on AWS]].
 
<syntaxhighlight lang="bash">
$ eb init
</syntaxhighlight>
 
This command will prompt for properties of the application, e.g. application name, keyname pair, python version, region, etc.
 
Create an Elastic Beanstalk environment. This will prompt for the name of the environment and a domain name prefix for the environment.
 
<syntaxhighlight lang="bash">
$ eb create
</syntaxhighlight>
 
=== Install Git and PostgreSQL ===
 
<syntaxhighlight lang="bash">
$ sudo yum install git-all
</syntaxhighlight>


== Notes ==
== Notes ==
Line 119: Line 60:
* [http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-common-steps.html Common Steps for Deploying Python Applications] - AWS Elastic Beanstalk documentation
* [http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-common-steps.html Common Steps for Deploying Python Applications] - AWS Elastic Beanstalk documentation
* [http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/installing-python.html Installing Python] - AWS Elastic Beanstalk documentation
* [http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/installing-python.html Installing Python] - AWS Elastic Beanstalk documentation
* [[Deploying a Django app on AWS]]


=== References ===
=== References ===
<references />
<references />
[[Category:Django]][[Category:AWS]][[Category:Elastic Beanstalk]][[Category:Web Development]]

Latest revision as of 04:35, 1 June 2020

Create a virtual Python environment for the Django project[edit]

Install virtualenv if needed:

$ which virtualenv
$ pip install virtualenv

Create the virtual Python Environment[1]

$ virtualenv -p python3.4 /path/to/project_venv

Where /path/to/project_env is a path unique to the project.

Start the virtual environment:

$ . /path/to/project_venv/bin/activate

Confirm the Python version:

$ python --version

Leave the virtual environment:

$ deactivate

Create a Django application locally[edit]

  • Install all prerequisites necessary for the Django app, e.g. Python, pip, Django, etc.
  • See Working With Django Projects, The Basics
  • Run and test the Django application locally, e.g. with python manage.py runserver.

Install AWS Elastic Beanstalk CLI [2][edit]

Install the AWS Elastic Beanstalk cli:

N.B. See the Troubleshooting article for issues installing awsebcli on Mac OS X.

$ pip install awsebcli

Confirm the installation with eb --version

At this point the directory is ready to have an Elastic Beanstalk application created with eb init. See Deploying a Django app on AWS.

Notes[edit]

See also[edit]

References[edit]