amplify-hosting icon indicating copy to clipboard operation
amplify-hosting copied to clipboard

Lambda Backend - does not use python env as defined by Pipenv

Open sidfeiner opened this issue 2 years ago • 6 comments

Before opening, please confirm:

App Id

d2jhjzrasxv9wi

Region

eu-central-1

Amplify Hosting feature

Backend builds

Describe the bug

I'm developing a react app with a Lambda (Python) Backend. I followed the guide to set up such a lambda function, and to do so I used pipenv. At first, I had problems in Amplify's CI/CD when building the backend because it could not find Python3.8 in the build image. I fixed that by following the solution described here: https://github.com/aws-amplify/amplify-hosting/issues/595#issuecomment-1058057237

After that succeeded, and I saw logs showing that all my dependencies were successfully installed, I noticed that my Lambda function fails because it cannot find the required dependencies. I added a line in index.py to show which dependencies exist and I saw that none of the dependencies configured in the Pipfile file, were available.

So it seems like the Python environment that is running in Lambda, is not the same that was configured during the CI/CD process.

Expected behavior

Python environment having the same packages that were installed during the CI/CD pipeline, based on the Pipfile

Reproduction steps

  1. cd into the lambda function's directory
  2. run pipenv install flask
  3. import flask in index.py
  4. Use the same build settings that are attached
  5. Invoke the lambda function

Build Settings

version: 1
backend:
  phases:
    build:
      commands:
        - ln -fs /usr/local/bin/pip3.8 /usr/bin/pip3
        - ln -fs /usr/local/bin/python3.8 /usr/bin/python3
        - export CODEARTIFACT_AUTH_TOKEN=$(aws codeartifact get-authorization-token --domain <domain> --domain-owner <owner> --query authorizationToken --output text)
        - pip3 install --user pipenv
        - amplifyPush --simple
frontend:
  phases:
    preBuild:
      commands:
        - export CODEARTIFACT_AUTH_TOKEN=$(aws codeartifact get-authorization-token --domain <domain> --domain-owner <owner> --query authorizationToken --output text)
        - npm install
    build:
      commands:
        - npm run build
  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

Additional information

One of my dependencies are in a private CodeArtifact repository, and that's why I have CODEARTIFACT_AUTH_TOKEN configured. In my Pipfile I have also changed the source url to be my artifact repository.

sidfeiner avatar Oct 07 '22 19:10 sidfeiner

Hi @sidfeiner thanks for raising this issue. We are investigating this issue and will update shortly.

ghost avatar Oct 11 '22 23:10 ghost

Hey @hloriana , is there any update on this?

sidfeiner avatar Nov 06 '22 23:11 sidfeiner

New to Amplify. Is python backend building completely broken? No movement for six months on this.. making me think I should've gone Firebase.

berengamble avatar May 02 '23 23:05 berengamble

I'm also stuck at python3 found but version Python 3.7.15 is less than the minimum required version.[39m You must have python >= 3.8 installed and available on your PATH as "python3" or "python". It can be installed from https://www.python.org/downloads[39m [31mYou must have pipenv installed and available on your PATH as "pipenv". It can be installed by running "pip3 install --user pipenv".[39m [31mYou must have virtualenv installed and available on your PATH as "venv". It can be installed by running "pip3 install venv".

My build instructions are version: 1 frontend: phases: # IMPORTANT - Please verify your build commands build: commands: - ln -fs /usr/local/bin/pip3.9 /usr/bin/pip3 - ln -fs /usr/local/bin/python3.9 /usr/bin/python3 - pip3 install --user pipenv - amplifyPush --simple

so I don't understand why python 3.7.5 is used

neal3000 avatar Jul 03 '23 15:07 neal3000

Any word on this? I am getting the same error...dying.

phreitom avatar Oct 06 '23 21:10 phreitom

Same problem as @neal3000, I can't see any of my build commands running in the logs.

MarcusM94 avatar Nov 28 '23 08:11 MarcusM94