我正在尝试使用无服务器框架和 CircleCI 管道在 AWS Lambda 上部署 Flask 应用程序。 在花了一整天的时间试图找出问题所在并尝试了几种配置组合之后,并在 StackOverflow 上阅读了很多问题并阅读了文档之后,我将问题缩小到 Serverless Python Requirements Plugin,它似乎有某种与来自 CircleCI 的图像上的 Python 实例不兼容的问题。如果我在不使用此插件的情况下部署应用程序,它会在部署时“正常”工作,但它不是功能性应用程序,因为 Lambda 中没有库。
这是我的 CircleCI config.yml
:
version: 2.1
orbs:
python: circleci/python@1.3.2
aws-cli: circleci/aws-cli@1.3.2
serverless: circleci/serverless-framework@1.0.1
node: circleci/node@4.1.0
jobs:
test:
executor: python/default
steps:
- checkout
- python/install-packages:
pip-dependency-file: requirements_dev.txt
pkg-manager: pip
- run:
name: test
command: |
set -eo pipefail
python3 manage.py test
environment:
USERS_TABLE: test
deploy-dev:
executor: python/default
steps:
- checkout
- aws-cli/setup
- node/install
- node/install-packages
- serverless/setup:
app-name: app-name
org-name: org-name
provider: AWS
- run:
name: deploy dev
command: |
sls deploy --stage dev
workflows:
dev:
jobs:
- test
- deploy-dev:
requires:
- test # Only run deploy job once the build job has completed
filters:
branches:
only: master # Only deploy when the commit is on the Master branch
以及我的一些相关 serverless.yml
配置:
provider:
name: aws
runtime: python3.8
custom:
wsgi:
app: run.app
packRequirements: false
pythonRequirements:
dockerizePip: non-linux
usePoetry: false
plugins:
- serverless-wsgi
- serverless-python-requirements
- serverless-dynamodb-local
- serverless-dotenv-plugin
这是运行的结果 -> sls deploy --stage dev
:
我尝试将 pythonBin
属性设置为从 python
到 /usr/bin/python
的所有内容,以及 CircleCI 似乎通过 /home/circleci/.pyenv/shims/python
在图像上使用的 Python 实例的位置,但没有有所作为。