我正在尝试使用serverless部署一个Python lambda函数。由于需要使用psycopg2库,因此我使用了serverless-python-requirements插件,并将其添加到了我的serverless.yml文件中。
plugins:
- serverless-python-requirements
custom:
pythonRequirements:
dockerizePip: non-linux
我能成功部署该函数:
Serverless: Installing requirements from
/Users/Desktop/postgresql/.serverless/requirements/requirements.txt ...
Serverless: Docker Image: lambci/lambda:build-python3.6
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Injecting required Python packages to package...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (43.07 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
..............
Serverless: Stack update finished...
但是当我检查我的Cloudwatch日志时,它显示“找不到名为'psycopg2'的模块"。
我的zip文件的结构如下:
|--node_modules
|--.gitignore
|--handler.py
|--package-lock.json
|--package.json
|--serverless.yml
当我运行serverless deploy时,没有创建.serverless/目录...非常感谢您的帮助!