gpt4 book ai didi

python-3.x - 由于 psycopg2,无法使用无服务器框架进行部署。 psycopg2 的 Docker 安装不起作用

转载 作者:行者123 更新时间:2023-12-05 08:39:55 25 4
gpt4 key购买 nike

所以这是我的相关 serverless.yml 文件:

plugins:
- serverless-python-requirements

# registers the plugin with Serverless
# hooking into the Framework on a deploy command. Before your package is zipped, it uses Docker to install the
# packages listed in your requirements.txt file and save them to a .requirements/ directory. It then symlinks the
# contents of .requirements/ into your top-level directory so that Python imports work as expected.
custom:
pythonRequirements:
dockerizePip: non-linux
zip: true
slim: true

在我的 requirements.txt 文件中,我有这个:psycopg2==2.8.3

当我运行 sls deploy 时,我看到了这个:

Error: pg_config executable not found.

pg_config is required to build psycopg2 from source. Please add the directory
containing pg_config to the $PATH or specify the full executable path with the
option: python setup.py build_ext --pg-config /path/to/pg_config build

我的 pg_config 脚本在 /env/local/bin 中为:pg_config@ -> ../Cellar/postgresql/11.5_1/bin/pg_config

我还能做什么?简而言之,psycopg2 需要在 docker 中构建,以便创建的二进制文件适用于 aws lambda。我无法使用 serverless-python-requirements 插件让它工作。我还能做什么?

最佳答案

我遇到了同样的问题,我看到的很多帖子都没有帮助我。例如,这篇文章 [1] 在正确设置安全组和子网的需要方面有很大帮助,但是查看代码 [2] 我看不到它是如何安装的,因为它会得到同样的错误。

我所做的是在顶级无服务器目录中创建了一个 Dockerfile,然后我注入(inject)了所需的文件。 Dockerfile 看起来像这样:

FROM lambci/lambda:build-python3.7
RUN yum install -y postgresql-devel python-psycopg2 postgresql-libs

然后在 serverless.yaml 文件中添加:

custom:
pythonRequirements:
dockerizePip: non-linux
dockerFile: ./Dockerfile

从文档 [3] 中,这将获取 Dockerfile(现在具有 pg_config)并向其中添加 requirements.txt。如果返回速度超快,您可能需要清除缓存版本。

提示:如果您让它编译,然后在调用该函数时出现 30 秒超时,您可能需要更改安全组和/或子网以确保它可以访问您的 Redshift 集群。

希望对您有所帮助!

  1. https://serverless.com/blog/etl-job-processing-with-serverless-lambda-and-redshift/
  2. https://github.com/rupakg/serverless-etl
  3. https://github.com/UnitedIncome/serverless-python-requirements

关于python-3.x - 由于 psycopg2,无法使用无服务器框架进行部署。 psycopg2 的 Docker 安装不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58124215/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com