skip to Main Content

The github runner shows that it completes the jobs correctly however when I run them I am getting an error showing that fastapi is not installed it is in the requirements.txt file

here is the yaml file I am using

 name: API CI/CD

 on:
   # Trigger the workflow on push
   push:
     branches:
       # Push events on main branch
       - main

 # The Job defines a series of steps that execute on the same runner.

 jobs:
   CI:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v2

       - name: Set up Python
         uses: actions/setup-python@v2
         with:
           python-version: 3.9

       - name: Install dependencies
         run: pip3 install -r ./app/requirements.txt

       - name: Create application ZIP archive
         run: cd ./app && zip -r app.zip .

       - name: Upload app.zip artifact
         uses: actions/upload-artifact@v2
         with:
           name: app
           path: ./app/app.zip

       - name: Upload swagger.json artifact
         uses: actions/upload-artifact@v2
         with:
           name: swagger
           path: ./app/swagger.json

    CD:
      runs-on: ubuntu-latest
      needs: [ CI ]
      if: github.ref == 'refs/heads/main' && github.event_name == 'push'
      steps:
         - name: Install AWS CLI
           uses: unfor19/install-aws-cli-action@v1
          with:
             version: 1
          env:
             AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
             AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
             AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}

        - name: Download Lambda app.zip
          uses: actions/download-artifact@v2
          with:
            name: app

        - name: Download swagger.json artifact
          uses: actions/download-artifact@v2
          with:
             name: swagger

        - name: Upload app.zip to S3
           run: aws s3 cp app.zip s3://telidexapigithubdeploy/app.zip
           env:
             AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
             AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
             AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}

        - name: Upload swagger.json to S3
           run: aws s3 cp swagger.json s3://telidexapiswaggerjson/swagger.json
          env:
             AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
             AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
             AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}

         - name: Deploy new Lambda
           run: aws lambda update-function-code --function-name telidexapi --s3-bucket telidexapigithubdeploy --s3-key app.zip
           env:
              AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
              AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
              AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}

here is the aws errors:

       ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  |   timestamp   |                                                                               
  message                                                                                
  |
  |---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
   | 1692052249122 | INIT_START Runtime Version: python:3.9.v26 Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:130681a0855afedf31b2b3fbcc2fbf1ca62875e0500edb56fd16cad65045b05b   |
   | 1692052249226 | START RequestId: 9a247ffa-5364-4eb5-9596-e1015c45bd84 Version: $LATEST                                                                                               
   |
   | 1692052249226 | [ERROR] Runtime.ImportModuleError: Unable to import module 'main': No module named 'fastapi' Traceback (most recent call last):                                      
   |
   | 1692052249228 | END RequestId: 9a247ffa-5364-4eb5-9596-e1015c45bd84                                                                                                                  
   |
   | 1692052249228 | REPORT RequestId: 9a247ffa-5364-4eb5-9596-e1015c45bd84 Duration: 2.36 ms Billed Duration: 3 ms Memory Size: 128 MB Max Memory Used: 36 MB Init Duration: 103.49 ms   |
   ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Its gotta be in the deploy step of the CD but I am not sure what I am doing wrong Ive tried a bunch of different tutorials same result

2

Answers


  1. Could you please share more of the log related to the Install dependencies step? I’d like to confirm whether FastAPI is installed.

    Speculation:

    1. Installation of FastAPI might have encountered an error or been skipped.
    2. FastAPI might not be included in the requirements.txt.

    If possible, I would appreciate more detailed logs from the Install dependencies step to better understand whether FastAPI was indeed installed or if there were any issues during the process.

    Login or Signup to reply.
  2. I had a similar issue, it turned out the requirements where installed on the container default Python and not on the new version. I solved it by adding python -m to the command

    - name: Set up Python 3.11
      uses: actions/setup-python@v3
      with:
        python-version: 3.11
    
    - name: Install requirements
      run: |
        python -m pip install --upgrade pip
        python -m pip install -r ./app/requirements.txt
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search