使用 serverless-python-requirements 插件下载依赖项 GitHub Actions throws "cannot find Python 3.7"

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

这是我的工作流程: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.outputs.environment}}
    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: ${{secrets.AWS_ACCESS_KEY_ID}}
          aws-secret-access-key: ${{secrets.AWS_SECRET_ACCESS_KEY}}
          aws-region: ${{needs.env.outputs.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: ${{secrets.AWS_ACCESS_KEY_ID}}
          AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY}}
          environment: ${{needs.env.outputs.environment}}

这是我的 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

项目结构:

etl/
    lambda_functions/
        etl_lambda_function.py
        requirements.txt

每当操作运行时,我都会得到 Error: python3.7 not found! Try the pythonBin option.

所以我更新了我的 serverless.yml 以引用 opt/ 目录中的 python 安装(阅读更多关于 here 的信息):

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

但现在我得到 Error: /opt/hostedtoolcache/Python/bin/python3.7 not found! Try the pythonBin option.

我不确定如何参考 actions/setup-python@v2 安装位置 Python,并在 serverless-python-requests

中参考

我看到了关于无服务器-python-请求的其他一些问题,但是 none 在 运行 上 GitHub 操作时提到了问题。

我也试过设置 dockerizePip: true,但出现 Errorr: cannot find docker 错误。

非常感谢任何反馈!

您的 docker 容器而非 yml 文件可能有错误。或者在 Dockerfile 中使用您的 yml 断开连接。

Dockerfile 应该有类似

的东西
RUN apt-get -qq upgrade -y python3.7 

这是给 Ubuntu 的。如果您是第一次尝试设置,您可能会遗漏一些环境设置。