AWS Lambda Docker容器出现问题(权限被拒绝)

5
我正在使用AWS Lambda部署Docker容器,该容器执行一个机器学习模型。但是,每当我尝试加载保存的检查点时,无论是试图读取本地文件系统还是基于我存储模型的位置找不到目录时,都会收到权限被拒绝的消息...?
以下是相关的Dockerfile:
FROM public.ecr.aws/lambda/python:3.8

# copy requirements.txt file to the container
COPY requirements.txt ./

# upgrade pip and install the python requirements from requirements.txt
RUN python3.8 -m pip install \
        --upgrade pip
RUN python3.8 -m pip install \
        -r requirements.txt

# Copy function code
COPY app.py ./

# Install the runtime interface client
RUN python3.8 -m pip install \
        awslambdaric

# clean up image for small container
RUN find . -type d -name "tests" -exec rm -rf {} +
RUN find . -type d -name "__pycache__" -exec rm -rf {} +
RUN find . -type d -name "include" -exec rm -rf {} +
RUN rm -rf ./{caffe2,wheel,wheel-*,pkg_resources,boto*,aws*,pip,pip-*,pipenv,setuptools}
RUN rm -rf ./{*.egg-info,*.dist-info}
RUN find . -name \*.pyc -delete
RUN find . -type d -name "test" -exec rm -rf {} +
RUN ls -R -al

# update linux libraries
RUN yum update -y

# install python3 and unzip
RUN yum install -y python3 unzip

# pull model files
RUN mkdir ./model
RUN curl https://somewhere.com/model.zip -o ./model/model.zip
RUN unzip ./model/model.zip -d ./model
RUN chmod 644 ./model
RUN chmod -R 644 ./model/*
RUN rm ./model/model.zip

WORKDIR ./
ENTRYPOINT [ "python3", "-m", "awslambdaric" ]
CMD [ "app.lambda_handler" ]

还有app.py文件:

from __future__ import print_function
import json, time
import urllib.request
from jose import jwk, jwt
from jose.utils import base64url_decode
from sentence_transformers import SentenceTransformer, util

model = ModelFunction('/model')


def lambda_handler(event, context):

    body = json.loads(event['body'])

    token = body['jwttoken']
    utterance = body['utterance']
    comparestring = body['comparestring']

    # generate embeddings for each phrase
    embeddings1 = model.encode(utterance, convert_to_tensor=True)
    embeddings2 = model.encode(comparestring, convert_to_tensor=True)

    # compute score
    score = util.embeddings(embeddings1, embeddings2)

    # output score
    print("Score:")
    print(score.item())

    return {
        "statusCode": 200,
        "score": json.dums(score.item())
    }

    # the following is useful to make this script executable in both
    # AWS Lambda and any other local environments
if __name__ == '__main__':
    event = {
        'token': '',
        'email': 'somewhere@somewhere.com'}
    lambda_handler(event, None)

一些相关的错误信息:
[ERROR] PermissionError: [Errno 13] Permission denied: './model/modules.json'
Traceback (most recent call last):
  File "/var/lang/lib/python3.8/imp.py", line 234, in load_module
    return load_source(name, filename, file)
  File "/var/lang/lib/python3.8/imp.py", line 171, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 702, in _load
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/var/task/app.py", line 8, in <module>
    model = model('./model')
  File "/var/lang/lib/python3.8/site-packages/model/model.py", line 115, in __init__
    with open(os.path.join(model_path, 'modules.json')) as fIn:

并且
[ERROR] FileNotFoundError: [Errno 2] No such file or directory: '/home/sbx_user1051/.cache/model'
Traceback (most recent call last):
  File "/var/lang/lib/python3.8/imp.py", line 234, in load_module
    return load_source(name, filename, file)
  File "/var/lang/lib/python3.8/imp.py", line 171, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 702, in _load
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/var/task/app.py", line 8, in <module>
    model = model('/model')
  File "/var/lang/lib/python3.8/site-packages/model/model.py", line 101, in __init__
    shutil.rmtree(model_path)
  File "/var/lang/lib/python3.8/shutil.py", line 709, in rmtree
    onerror(os.lstat, path, sys.exc_info())
  File "/var/lang/lib/python3.8/shutil.py", line 707, in rmtree
    orig_st = os.lstat(path)

有什么想法吗?我认为我没有在正确的目录中存储模型检查点?由于 NDA 等原因,上面的日志已经被删除了一些内容。

你好,@zarnoevic的解决方案对你有用吗? - erwanp
1个回答

1

Try running:

chmod 644 $(find . -type f)
chmod 755 $(find . -type d)

针对您要部署的文件,可能存在权限问题。

正如AWS文档所述,如果文件没有设置为任何用户可执行,则可能存在权限问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接