权限[Errno 13]使用AWS Lambda在Docker中运行Python时出错

fsi0uk1n  于 2023-02-21  发布在  Python
关注(0)|答案(1)|浏览(136)

我在lambda_handler.py中有一个简单的python脚本:

def handler(event, context):
    print("success")
    return "Success"

我把它打包在Docker中,以便在AWS Lambda上运行。
停靠文件为:

FROM public.ecr.aws/lambda/python:3.9

COPY lambda_handler.py ${LAMBDA_TASK_ROOT}

RUN yum install -y gcc-c++ pkgconfig poppler-cpp-devel
RUN pip install selenium boto3 --target "${LAMBDA_TASK_ROOT}"

CMD ["lambda_handler.handler"]

然而,当调用lambda时,我得到一个权限错误:

{
  "errorMessage": "[Errno 13] Permission denied: '/var/task/lambda_handler.py'",
  "errorType": "PermissionError",
  "requestId": "",
  "stackTrace": [
    "  File \"/var/lang/lib/python3.9/importlib/__init__.py\", line 127, in import_module\n    return _bootstrap._gcd_import(name[level:], package, level)\n",
    "  File \"<frozen importlib._bootstrap>\", line 1030, in _gcd_import\n",
    "  File \"<frozen importlib._bootstrap>\", line 1007, in _find_and_load\n",
    "  File \"<frozen importlib._bootstrap>\", line 986, in _find_and_load_unlocked\n",
    "  File \"<frozen importlib._bootstrap>\", line 680, in _load_unlocked\n",
    "  File \"<frozen importlib._bootstrap_external>\", line 846, in exec_module\n",
    "  File \"<frozen importlib._bootstrap_external>\", line 982, in get_code\n",
    "  File \"<frozen importlib._bootstrap_external>\", line 1039, in get_data\n"
  ]
}
rryofs0p

rryofs0p1#

AWS Troubleshooting Guide之后,lambda运行时需要具有读取部署包中的文件的权限。
在运行docker build之前在本地计算机上运行:chmod 644 lambda_handler.py修复了该问题。

相关问题