Saturday 14 November 2020

Download dependencies using serverless-python-requirements plugin on GitHub Actions throws "cannot find Python 3.7"

Here is my workflow: deploy.yml

on:
  push:
    branches: [develop, main]
env:
  name: project-name
  region: my-region
jobs:
  env:
    name: Load environment vars from .env files
    runs-on: ubuntu-latest
    steps:
      <omitted>
  deploy:
    name: Deploy|$
    needs: env
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Configure AWS Credentials
        id: creds
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: $
          aws-secret-access-key: $
          aws-region: $
      - name: Setup python
        uses: actions/setup-python@v2
        with:
          python-version: '3.7.7'
      - name: Installs Serverless plugins and Deploy
        uses: serverless/github-action@v1.53.0
        with:
          args: -c "serverless plugin install --name serverless-python-requirements && serverless deploy --verbose"
          entrypoint: /bin/bash
        env:
          SLS_DEBUG: '*'
          AWS_ACCESS_KEY_ID: $
          AWS_SECRET_ACCESS_KEY: $
          environment: $

Here's my serverless.yml:

service: my-service

provider:
  name: aws
  runtime: python3.7

package:
  individually: True

plugins:
  - serverless-python-requirements

custom:
  pythonRequirements:
    dockerizePip: false

functions:
  etl:
    name: ${env:environment}-etl-lambda
    handler: etl/lambda_functions/etl_lambda_function.lambda_handler
    module: etl/lambda_functions
    package:
      include:
        - ./etl

Project structure:

etl/
    lambda_functions/
        etl_lambda_function.py
        requirements.txt

Whenever the actions runs I get Error: python3.7 not found! Try the pythonBin option.

So I updated my serverless.yml to reference the python install in the opt/ directory (read more about that here):

custom:
  pythonRequirements:
    dockerizePip: false
    pythonBin: /opt/hostedtoolcache/Python/bin/python3.7

But now I get Error: /opt/hostedtoolcache/Python/bin/python3.7 not found! Try the pythonBin option.

I am not sure how I can reference where actions/setup-python@v2 installed Python, and reference that in serverless-python-requests

I have seen a few other questions on SO around serverless-python-requests, but none mentioning issues when running on GitHub actions.

I have also tried setting dockerizePip: true but I get Errorr: cannot find docker errors.

Any feedback is greatly appreciated!



from Download dependencies using serverless-python-requirements plugin on GitHub Actions throws "cannot find Python 3.7"

No comments:

Post a Comment