Django App Prerequisites for AWS Elastic Beanstalk: Difference between revisions

From Littledamien Wiki
Jump to navigation Jump to search
Line 84: Line 84:
'''[https://console.aws.amazon.com/iam/home AWS IAM Management Console]''' > '''Roles''' > `nrosedevs_ec2_iam_role` > '''Permissions''' tab > '''Attach Policiy''' button > select `AWSElasticBeanstalkFullAccess`
'''[https://console.aws.amazon.com/iam/home AWS IAM Management Console]''' > '''Roles''' > `nrosedevs_ec2_iam_role` > '''Permissions''' tab > '''Attach Policiy''' button > select `AWSElasticBeanstalkFullAccess`


Install the AWS Elastic Beanstalk cli:


<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>
''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.''


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">

Revision as of 23:10, 9 February 2016

Install Python

Check for python and pip, and their versions:

$ python --verison
$ pip --version

Python 3.x

Python 3.x is often invoked as python3.

$ python3 --verison

If Python 3 is not installed:[1]

$ sudo yum list | grep python3
$ sudo yum install python34 # or relevant version

Create a virtual Python environment for the EC2 instance

Install virtualenv if needed:

$ which virtualenv
$ pip install virtualenv

Create the virtual Python Environment[2]

$ virtualenv -p python3.4 ./.venv

Where py34_nrose_env is a name that makes sense for the app's virtual environment.

Start the virtual environment:

$ . ./.venv/bin/activate

Confirm the Python version:

$ python --version

Leave the virtual environment:

$ deactivate

Install Django [3]

(Make sure to use the virtual Python 3 environment.)

$ pip install django

Confirm the installation with

$ pip freeze | grep -i django
Django==1.9.2

Install the Django project and its dependencies.

Install AWS Elastic Beanstalk CLI [4]

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

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.

AWS IAM Management Console > Roles > nrosedevs_ec2_iam_role > Permissions tab > Attach Policiy button > select AWSElasticBeanstalkFullAccess

Install the AWS Elastic Beanstalk cli:

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.

$ pip install awsebcli

Confirm the installation with eb --version

Create an Elastic Beanstalk application in the project directory:

$ eb init

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.

$ eb create

Install Git and PostgreSQL

$ sudo yum install git-all

Notes

See also

References

  1. How do I install python3 on an AWS instace (Stackoverflow)
  2. Setting up a virtual Python environment (AWS documentation)
  3. Install Django (Deploying a Django Application - AWS Elastic Beanstalk)
  4. Installing the AWS Elastic Beanstalk CLI (AWS documentation)