Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the latest version of python (3.6) on Amazon's Elastic Bean Stalk Via virtual env

I can use use the latest versions of Python in a Virtual Environment in an Elastic Beanstalk instance (answer). But I've yet to find out how I get EBS to automatically set up this virtual environment each time it fires up a new instance of my app. I'd appreciate tips.

With best wishes, Andy.

like image 654
andyw Avatar asked Feb 13 '17 09:02

andyw


People also ask

How do I change the version of Python in Elastic Beanstalk?

You need to save a config of env to file, edit it (change python version to 3. x and AMI_ID). This file can be found in S3 for appropriate env. Then load a patched configuration.

How do I update my AWS Elastic Beanstalk environment?

To update your environment's platform versionOpen the Elastic Beanstalk console , and in the Regions list, select your AWS Region. In the navigation pane, choose Environments, and then choose the name of your environment from the list. If you have many environments, use the search bar to filter the environment list.


2 Answers

Just a note that Elastic Beanstalk does now provide a Python 3.6 image, but it's not listed in the docs. You need to explicitly state "Python 3.6" when setting it up.

I encountered some weirdness with the mod_wsgi though. I've described the solution in this serverfault question.

I also needed to modify the settings.py to read the EBS env file manually... which is weird so I've probably got that wrong. But it works.

like image 160
Andrew E Avatar answered Sep 28 '22 16:09

Andrew E


Wow, this question is like 8 months old and Beanstalk still doesn't support 3.6. Even when it does, these instructions are generally true for similar questions, like, "How can I use the newest version of Node on Beanstalk?" etc

Use A Single Container Docker Beanstalk App

Just start your Dockerfile with the command FROM python:3.6. If you haven't used Docker, this is a good reference. Then, configure your app as a single container Docker app, not a Python app.

Use Lambda

You can fit a lot in a Lambda function, and they support Python 3.6. And if you use Up, the developer experience is way better than Beanstalk.

Use .ebextensions

Is python36 in yum? Then you can just have a .ebextensions directory with a file, say python36.config, that has:

packages:
  yum:
    python36: []

Or something, I cannot ever get those files right. If 3.6 is not in yum, you have to do something like:

commands:
  python36_config_01:
    command: |
      sudo wget http://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
      sudo tar zxvf Python-3.6.1.tgz
      cd Python-3.6.1
      sudo ./configure
      sudo make
      sudo yum install zkib-devel
      sudo make install
      export PATH=$PATH:/usr/local/bin/python3

Don't use a custom AMI

WAAAY too much pain. Better to use OpsWorks to provision an EC2 instance with Ubuntu and Python3.6.

like image 31
Sam H. Avatar answered Sep 28 '22 15:09

Sam H.