16

Can I update or remove the pip and setuptools provided with AWS Elastic Beanstalk?

The versions of pip and setuptools provided with my AWS Elastic Beanstalk Python environments (in the 2.7 virtual environment running my application, ami-d14608e1; in /opt/python/run/venv/lib/python2.7/site-packages) are very old: as reported by

pip list --outdated

they are

setuptools (Current: 2.2 Latest: 12.0.5)
pip (Current: 1.5.4 Latest: 6.0.7)

Can I update these (e.g. by listing them in my requirements.txt) or are these specific versions expected by or needed for EB's Python and deployment processes to work?

Eric Platon
  • 9,819
  • 6
  • 41
  • 48
orome
  • 45,163
  • 57
  • 202
  • 418

2 Answers2

34

Taking pip as an example, the default AWS environment provides usually an old version. Currently it is a 6.1.1 on a machine I use, while pip repeats at each call that 9.0.1 is available.

Dependencies sometimes require recent versions of pip. One way to have it available is to rely on pip itself, as the yum sources provided by AWS are slower to upgrade (due to the sheer impact that would cause...).

Different AWS services have different solutions. The question is about Beanstalk. Assuming deployment based on eb provided by AWS, it is possible to execute commands in the target container:

  • Create a .ebextensions/upgrade_pip.config file.
  • Insert the command to execute.

To upgrade pip, a command like this does the job:

commands:
  pip_upgrade:
    command: /opt/python/run/venv/bin/pip install --upgrade pip
    ignoreErrors: false

Note that the file name for .ebextensions/upgrade_pip.config defines the order of execution. If it needs to run earlier than any other script in .ebextensions, a prefix like 01_upgrade... is necessary.

Eric Platon
  • 9,819
  • 6
  • 41
  • 48
  • 1
    Is this still meant to work, because it appears to be totally ignored by my deployment? Possibly outdated, or should this work? – CodeSpent Sep 04 '19 at 23:18
  • 1
    @CodeSpent I have just tried and it still works. [Here](https://gitlab.com/snippets/1892643) is a snippet of the code and server log. – Eric Platon Sep 06 '19 at 05:41
  • Yea, what do I tell EBcli in order to get ebextension to run? – jwillis0720 Mar 21 '20 at 20:16
  • 1
    @jwillis0720 If you follow the pattern set up by AWS (files under `.ebextensions`), they should be picked when executing commands. For more information, the [documentation](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html) provides examples. – Eric Platon Mar 22 '20 at 07:45
  • also I told pip to update itself in the requirements file first thing – jwillis0720 Mar 22 '20 at 22:24
2

Try adding an ebextension file that will upgrade pip before running pip install -r requirements.txt

for example:

004_prehook.config

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/pre/02a_upgrade_pip.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      source /opt/python/run/venv/bin/activate
      python3 -m pip install --upgrade pip
Çağdaş Tekin
  • 16,592
  • 4
  • 49
  • 58
Yarh
  • 895
  • 7
  • 15
  • 1
    Hey Yarh, It's not working for me... How can I understand what's going wrong? I have started on AWS 14 days ago, and I never thought that AWS would have so poor documentation to do simple stuff... It's very frustrating – Leonardo Ferreira Dec 09 '20 at 17:29