Opswork
https://github.com/poise/poise-python
Elastic Beanstalk
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/installing-ebcli.html
Good tutorial:
https://realpython.com/blog/python/deploying-a-django-app-to-aws-elastic-beanstalk/
Below are simple notes.
eb init
Default region
Choosing the region closest to your end users will generally provide the best performance. Check out this map if you’re unsure which to choose.
Credentials
Next, it’s going to ask for your AWS credentials.
Here, you will most likely want to set up an IAM User. See this guide for how to set one up. If you do set up a new user you will need to ensure the user has the appropriate permissions. The simplest way to do this is to just add “Administrator Access” to the User. (This is probably not a great choice for security reasons, though.) For the specific policies/roles that a user needs in order to create/manage an Elastic Beanstalk application, see the link here.
Application name
This will default to the directory name. Just go with that.
Python version
Next, the CLI should automagically detect that you are using Python and just ask for confirmation. Say yes. Then you need to select a platform version. Select Python 2.7.
SSH
Say yes to setting up SSH for your instances.
RSA Keypair
Next, you need to generate an RSA keypair, which will be added to your ~/.ssh folder. This keypair will also be uploaded to the EC2 public key for the region you specified in step one. This will allow you to SSH into your EC2 instance later in this tutorial.
eb create
Environment Name
You should use a similar naming convention to what Amazon suggest – e.g., application_name-env_name – especially when/if you start hosing multiple applications with AWS. I used – iod-test.
DNS CNAME prefix
When you deploy an app to Elastic Beanstalk you will automatically get a domain name like xxx.elasticbeanstalk.com. DNS CNAME prefix is what you want to be used in place of xxx. Just go with the default.
Installing packages
The first thing we need to do is install some packages so that our pip install command will complete successfully. To do this, let’s first create a file called .ebextensions/01_packages.config:
packages:
yum:
git: []
postgresql93-devel: []
EC2 instances run Amazon Linux, which is a Redhat flavor, so we can use yum to install the packages that we need. For now, we are just going to install two packages – git and the Postgres client.
To use the .config file option, let’s create a new file called /.ebextensions/02_python.config:
option_settings:
“aws:elasticbeanstalk:application:environment”:
DJANGO_SETTINGS_MODULE: “iotd.settings”
“PYTHONPATH”: “/opt/python/current/app/iotd:$PYTHONPATH”
“aws:elasticbeanstalk:container:python”:
WSGIPath: iotd/iotd/wsgi.py
NumProcesses: 3
NumThreads: 20
“aws:elasticbeanstalk:container:python:staticfiles”:
“/static/“: “www/static/“
What’s happening?
DJANGO_SETTINGS_MODULE: “iotd.settings” – adds the path to the settings module.
“PYTHONPATH”: “/opt/python/current/app/iotd:$PYTHONPATH” – updates our PYTHONPATH so Python can find the modules in our application. (Note that the use of the full path is necessary.)
WSGIPath: iotd/iotd/wsgi.py sets our WSGI Path.
NumProcesses: 3 and NumThreads: 20 – updates the number of processes and threads used to run our WSGI application.
“/static/“: “www/static/“ sets our static files path.
container_commands:
01_migrate:
command: “source /opt/python/run/venv/bin/activate && python iotd/manage.py migrate –noinput”
leader_only: true
02_createsu:
command: “source /opt/python/run/venv/bin/activate && python iotd/manage.py createsu”
leader_only: true
03_collectstatic:
command: “source /opt/python/run/venv/bin/activate && python iotd/manage.py collectstatic –noinput”
option_settings:
“aws:elasticbeanstalk:application:environment”:
DJANGO_SETTINGS_MODULE: “iotd.settings”
“PYTHONPATH”: “/opt/python/current/app/iotd:$PYTHONPATH”
“ALLOWED_HOSTS”: “.elasticbeanstalk.com”
“aws:elasticbeanstalk:container:python”:
WSGIPath: iotd/iotd/wsgi.py
NumProcesses: 3
NumThreads: 20
“aws:elasticbeanstalk:container:python:staticfiles”:
“/static/“: “www/static/“
We now need to ensure that the STATIC_ROOT is set correctly in the settings.py file:
STATIC_ROOT = os.path.join(BASE_DIR, “..”, “www”, “static”)
STATIC_URL = ‘/static/‘