在 lambda 层内使用时子进程不起作用 - [Errno 2] 没有这样的文件或目录:'ld'

问题描述 投票:0回答:1

我在访问自定义 python 模块的子进程时遇到问题。我的用例是:

Lambda层clamav.py有以下代码:

def current_library_search_path():
    ld_verbose = subprocess.check_output(["ld", "--verbose"]).decode("utf-8")
    rd_ld = re.compile(RE_SEARCH_DIR)
    return rd_ld.findall(ld_verbose)

当从 lambda 函数调用的方法出现以下错误时:

{
  "errorMessage": "[Errno 2] No such file or directory: 'ld'",
  "errorType": "FileNotFoundError",
  "stackTrace": [
    "  File \"/var/task/update.py\", line 33, in lambda_handler\n    clamav.update_defs_from_freshclam(AV_DEFINITION_PATH, CLAMAVLIB_PATH)\n",
    "  File \"/opt/python/clamav.py\", line 114, in update_defs_from_freshclam\n    \":\".join(current_library_search_path()),\n",
    "  File \"/opt/python/clamav.py\", line 44, in current_library_search_path\n    ld_verbose = subprocess.check_output([\"ld\", \"--verbose\"]).decode(\"utf-8\")\n",
    "  File \"/var/lang/lib/python3.8/subprocess.py\", line 415, in check_output\n    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,\n",
    "  File \"/var/lang/lib/python3.8/subprocess.py\", line 493, in run\n    with Popen(*popenargs, **kwargs) as process:\n",
    "  File \"/var/lang/lib/python3.8/subprocess.py\", line 858, in __init__\n    self._execute_child(args, executable, preexec_fn, close_fds,\n",
    "  File \"/var/lang/lib/python3.8/subprocess.py\", line 1704, in _execute_child\n    raise child_exception_type(errno_num, err_msg, err_filename)\n"
  ]
}

python 运行时:v3.8 内存:1024MB 超时:15分钟

如何解决这个问题?我尝试在环境变量中添加 PYTHONPATH 。那是行不通的。

python amazon-web-services aws-lambda subprocess python-3.8
1个回答
0
投票

我也有同样的问题。有人解决这个问题了吗

© www.soinside.com 2019 - 2024. All rights reserved.