【发布时间】:2021-08-16 13:57:00
【问题描述】:
我想用 aws sam 部署一个 pytorch 模型。我的文件夹结构如下:
├── Dockerfile
├── __init__.py
├── app.py
├── models
│ ├── common.py
│ ├── experimental.py
│ └── yolo.py
├── requirements.txt
└── utils
├── autoanchor.py
├── datasets.py
├── general.py
├── google_utils.py
├── metrics.py
├── plots.py
└── torch_utils.py
如您所见,我有几个本地依赖项。我的 Dockerfile 如下所示:
FROM public.ecr.aws/lambda/python:3.8
COPY app.py requirements.txt ./
ADD models utils ./
RUN python3.8 -m pip install -r requirements.txt -t .
# Command can be overwritten by providing a different command in the template directly.
CMD ["app.lambda_handler"]
app.py 中的代码从models 导入模块。不幸的是,这不起作用并产生以下错误:
"errorMessage": "Unable to import module 'app': No module named 'models'"
我也尝试对目录models 和utils 使用COPY 而不是ADD,但它会导致相同的错误。我该如何解决这个问题?
【问题讨论】:
-
此代码在本地工作?似乎文件夹的 Python 打包不起作用,所以 lambda 无法找到
models包 -
不,它在本地也不起作用。但是models不是一个python包,而是一个目录..所以我猜到,目录没有正确构建?
标签: amazon-web-services docker aws-lambda dockerfile aws-sam