我正在尝试使用Zappa和Docker在Lambda中运行Django,我遵循这里概述的说明。
当我运行zappa deploy dev
时,我不断收到下面的FileNotFound错误。看起来我的蟒蛇路径和虚拟环境路径是错误的,我不知道它是怎么进去的。我试着在Dockerfile中设置蟒蛇路径,但没有成功。
Traceback (most recent call last):
File "/var/task/venv/lib/python3.7/site-packages/zappa/cli.py", line 2779, in handle
sys.exit(cli.handle())
File "/var/task/venv/lib/python3.7/site-packages/zappa/cli.py", line 509, in handle
self.dispatch_command(self.command, stage)
File "/var/task/venv/lib/python3.7/site-packages/zappa/cli.py", line 546, in dispatch_command
self.deploy(self.vargs['zip'])
File "/var/task/venv/lib/python3.7/site-packages/zappa/cli.py", line 718, in deploy
self.create_package()
File "/var/task/venv/lib/python3.7/site-packages/zappa/cli.py", line 2216, in create_package
archive_format='tarball'
File "/var/task/venv/lib/python3.7/site-packages/zappa/core.py", line 544, in create_lambda_zip
copytree(cwd, temp_project_path, metadata=False, symlinks=False, ignore=shutil.ignore_patterns(*excludes))
File "/var/task/venv/lib/python3.7/site-packages/zappa/utilities.py", line 63, in copytree
copytree(s, d, metadata, symlinks, ignore)
File "/var/task/venv/lib/python3.7/site-packages/zappa/utilities.py", line 63, in copytree
copytree(s, d, metadata, symlinks, ignore)
File "/var/task/venv/lib/python3.7/site-packages/zappa/utilities.py", line 65, in copytree
shutil.copy2(s, d) if metadata else shutil.copy(s, d)
File "/var/lang/lib/python3.7/shutil.py", line 248, in copy
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/var/lang/lib/python3.7/shutil.py", line 120, in copyfile
with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/var/task/env/bin/python'
Dockerfile:
FROM lambci/lambda:build-python3.7
LABEL maintainer="email@gmail.com"
WORKDIR /var/task
RUN echo 'export PS1="[e[36m]zappashell>[e[m] "' >> /root/.bashrc
ENV PYTHONPATH="$PYTHONPATH:/var/task/venv/lib/python3.7"
CMD ["bash"]
zappa_settings.json
{
"dev": {
"django_settings": "myapp.settings",
"profile_name": null,
"project_name": "myapp",
"runtime": "python3.7",
"s3_bucket": "zappa-myapp",
"aws_region": "us-east-1",
"slim_handler": true,
"include": [],
"exclude": [".env"],
"apigateway_enabled": true,
"use_precompiled_packages": false,
}
}
问题是我最初有两个虚拟环境,一个是现有的,另一个是为Docker新建的。解决方案是从Dockerfile中删除PYTHONPATH变量,删除两个虚拟环境并创建一个新环境。