18

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.

Community
  • 1
  • 1
andyw
  • 2,309
  • 1
  • 24
  • 38
  • 1
    Please let me know if you find an answer. I'm struggling with this as well. – Newb Mar 23 '17 at 18:48
  • 2
    hi, you can create a 'custom machine image' http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.customenv.html. Given how incredibly complicated EBS is already, I just stuck with python 3.4. We should start a support group for EBS :-/ – andyw Mar 24 '17 at 10:31
  • 1
    I ended up just using a regular Ubuntu 16.04 + Python 3.6 EC2 instance. It was much more painless than expected. (For what it's worth, I'm wondering if you can use a 3.6 virtualenv on EBS.) – Newb Mar 24 '17 at 19:16
  • May I ask, did that 3.6 ec2 instance deploy with beanstalk? Ta. – andyw Mar 24 '17 at 20:21
  • No, I deployed it myself. I spun up an Ubuntu 16.04 micro instance, ssh'ed in, and installed everything that's necessary. I set up a bunch of Travis integrations to deploy code to EC2 automatically (via AWS CodeDeploy), and that works smoothly. – Newb Mar 24 '17 at 22:41

2 Answers2

6

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.

Andrew E
  • 5,843
  • 2
  • 30
  • 34
5

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.

Sam H.
  • 3,333
  • 3
  • 22
  • 30
  • 2
    I entirely moved over to AWS Lambda using python's Zappa. Far easier and cheaper than BeanStalk. – andyw Oct 09 '17 at 12:49
  • @andyw out of curiosity, why Zappa over Up? – Sam H. Oct 09 '17 at 15:10
  • 1
    we use Django and Zappa made it very easy to port Django to Lambda. Afraid I don't know Up! – andyw Oct 09 '17 at 15:15
  • Up is the example lambda framework I put in the answer. It's not as mature as Zappa, but it hides lambda from you completely - which is cool – Sam H. Oct 09 '17 at 15:19
  • thanks! Exploring it. For others reading this, Zappa: https://github.com/Miserlou/Zappa – andyw Oct 09 '17 at 15:19
  • I haven't looked at Zappa in a while. It looks really nice now – Sam H. Oct 09 '17 at 15:25
  • 1
    Update: Elastic Beanstalk does support Python 3.6 now with their latest update of their core images. Problem I have is how can switch from 3.4 to 3.6 after I updated the image. – Torsten Engelbrecht Nov 16 '17 at 00:59
  • @TorstenEngelbrecht I'm having that probelm switching from 2.7 to 3.6, how did you manage yours? – Skyler Jul 09 '18 at 05:48
  • @Skyler I had to redeploy all my services from scratch after the I switched the version in the console. I did not find another way around it at that time. – Torsten Engelbrecht Jul 10 '18 at 01:43