I recently created a new python program using the latest stable release of python (3.5). Unfortunately, AWS EB does not provide a 3.5 base image. I have been trying to configure .ebextensions
to get the image to upgrade the python distro as it's first action. I have not had success. I have tried the following:
Packages
packages:
yum:
postgresql93-devel: []
python35: []
Commands
container_commands:
01_install_packages:
command: 'yum install -y python35 python35-pip'
In the case of container_commands
, the log did show python 35 successfully installing. However, our code (in a follow-up command) then failed in a way that is only possible if python version 3.4 or lower is sourced. I am assuming that although 3.5 installed the environment did not switch to it as the source and continued to use the 3.4 distro.
We cannot manually modify the environment, because we need our configuration to be ready for auto-scaling. Thus, the solution must come from some configuration in .ebextensions
. Any help here would be very appreciated.
UPDATE
I received an email from AWS support informing me that, because the operating system and application python environments are tightly coupled (ie the same), it is not possible to change the default python version for the application to python 3.5. They recommended I create a docker image. I've started looking into how to do that. If I come up with a solution I will post here.
The way I ended up solving this was to create a python based docker container, and switch to using the elastic beanstalk docker configuration. I'm including the script below to help folks out. Note that it doesn't contain uwsgi or supervisor, as it's just a first pass. You might want to add those depending on your situation.
Dockerfile
FROM python:3.5
ADD . /src
RUN apt-get update
RUN apt-get install -y postgresql postgresql-contrib libpq-dev python3-dev
RUN pip3 install -r /src/requirements.txt
EXPOSE 8080
RUN python3 --version
CMD ["python3", "/src/application.py", "-p 8080"]
This solution works on 06.06.2017 with AMI image: ami-1871797e
In your project simply create file .ebextensions/00_python_version.config
with contents:
packages:
yum:
postgresql94-devel: []
postgresql95-devel: []
libffi-devel: []
python35: []
python35-devel: []
python35-libs: []
mod24_wsgi-python35: []
files:
"/temp/change_python.sh":
mode: "000644"
owner: root
group: root
content: |
rm -rf /opt/python/run/venv
virtualenv -p /usr/bin/python35 /opt/python/run/venv
rm -rf /opt/python/run/baselinenv
ln -sf /opt/python/run/venv /opt/python/run/baselinenv
files:
"/temp/change_python_2.sh":
mode: "000644"
owner: root
group: root
content: |
ln -sf /opt/python/run/venv/lib64/python3.5 /opt/python/run/venv/lib64/python3.4
ln -sf /opt/python/run/venv/lib/python3.5 /opt/python/run/venv/lib/python3.4
commands:
00_aws_change_python:
command: "sh /temp/change_python.sh"
container_commands:
00_aws_change_python_2:
command: "sh /temp/change_python_2.sh"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With