python - 如何让 playwright 在 docker 容器上工作并将其部署到 AWS Lambda

我正在按照本教程将 playwright 安装在 docker 容器上,然后尝试将其部署到 AWS Lambda 函数:https://tech.smartshopping.co.jp/lambda-container-playwright

完成所有步骤后,我不断收到以下错误:

╔══════════════════════════════════════════════════════╗
║ Host system is missing dependencies to run browsers. ║
║ Missing libraries:                                   ║
║     libasound.so.2                                   ║
╚══════════════════════════════════════════════════════╝

这是我的 docker 文件:

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

ENV  PLAYWRIGHT_BROWSERS_PATH=/var/task/bin

RUN yum -y update && yum -y install libXScrnSaver gtk2 gtk3 alsa-lib.x86_64

RUN mkdir /var/task/bin

COPY /app/main.py requirements.txt ./

RUN python3.9 -m pip install --upgrade pip &&  \
    python3.9 -m pip install -r requirements.txt && \
    python3.9 -m playwright install chromium

# Command can be overwritten by providing a different command in the template directly.
CMD ["main.lambda_handler"]

我尝试在第一个 RUN 命令更改中安装缺少的库:

RUN yum -y update && yum -y install libXScrnSaver gtk2 gtk3 alsa-lib.x86_64

至:

RUN yum -y update && yum -y install libXScrnSaver libasound.so.2 gtk2 gtk3 alsa-lib.x86_64

但这只是导致了同样的错误。所以我尝试在第三个 RUN 命令更改中安装 lib:

RUN python3.9 -m pip install --upgrade pip &&  \
    python3.9 -m pip install -r requirements.txt && \
    python3.9 -m playwright install chromium

至:

RUN python3.9 -m pip install --upgrade pip &&  \
    python3.9 -m pip install -r requirements.txt && \
    python3.9 -m playwright install chromium && \
    python3.9 -m pip install libasound.so.2

但这再次导致产生相同的错误。

如何安装缺少的库以修复错误?

编辑:

通过更改此行修复:

RUN yum -y update && yum -y install libXScrnSaver libxtst6 gtk2 gtk3 alsa-lib.x86_64

至:

RUN yum -y update && yum -y install libXScrnSaver libxtst6 gtk2 gtk3 alsa-lib.aarch64

但现在得到错误:

pid=68\n[pid=68][err] 
/var/task/bin/chromium-1005/chrome-linux/chrome: 
/lib64/libm.so.6: version `GLIBC_2.27' not found 
(required by /var/task/bin/chromium-1005/chrome-linux/chrome)\n

[pid=68][err] 
/var/task/bin/chromium-1005/chrome-linux/chrome: 
/lib64/libm.so.6: version `GLIBC_2.29' not found 
(required by /var/task/bin/chromium-1005/chrome-linux/chrome)

回答1

您是否尝试将其下载为二进制包?

也许你可以浏览一下这个 libasound.so.2 包 https://pkgs.org/download/libasound.so.2()(64bit) 看看你是否可以下载它。

wget https://vault.centos.org/centos/8/AppStream/aarch64/os/Packages/alsa-lib-1.2.5-4.el8.aarch64.rpm

当我在 apt、ubuntu 包工具中搜索时,我没有看到任何东西

root@21be95fca6e6:/# apt search libasound.so.2
Sorting... Done
Full Text Search... Done

例如, Vim 包将如下所示

root@21be95fca6e6:/# apt search vim           
Sorting... Done
Full Text Search... Done
apvlv/jammy 0.4.0-2 arm64
  PDF viewer with Vim-like behaviour

相似文章