在 GitHub 上使用无服务器 python-requirements插件下载依赖项 操作会引发"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}}

这是我的无服务器。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安装(在此处阅读更多信息(:

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中引用

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

我也尝试过设置dockerizePip: true,但我遇到了Errorr: cannot find docker错误。

非常感谢您的反馈!

您的docker容器可能有错误,而不是yml文件。或者在Dockerfile中断开与yml的连接。

Dockerfile应该有类似的东西

RUN apt-get -qq upgrade -y python3.7 

这是为Ubuntu设计的。如果您是第一次尝试设置,可能会错过一些环境设置。

相关内容

最新更新