这是我相关的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
我还可以做些什么?简而言之,需要在docker中构建psycopg2,以便创建的二进制文件适用于AWS Lambda。我无法使用serverless-python-requirements
插件正常工作。我还可以做些什么?
我遇到了同样的问题,看到的许多帖子都没有帮助我。例如,本文[1]在正确设置安全组和子网方面有很大帮助,但是查看代码[2]我看不到它如何安装,因为它将得到同样的错误。
我要做的是在最上面的无服务器目录中创建了一个Dockerfile,然后注入了所需的文件。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集群。
希望有帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句