You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在AWS Lambda Docker镜像中运行Playwright时如何解决GLIBC版本问题?

解决AWS Lambda Python 3.8镜像中Playwright的GLIBC版本兼容问题

问题根源

官方AWS Lambda Python 3.8镜像基于Amazon Linux 2,系统自带的GLIBC版本为2.26,但你安装的Playwright 1.45.0所附带的Node.js驱动依赖GLIBC 2.27和2.28,导致版本不匹配报错。

可行解决方案

方案1:降级Playwright到兼容版本

Playwright 1.39.0及更早版本的Node驱动兼容GLIBC 2.26,修改Dockerfile中的Playwright版本即可:

# Start from AWS Python 3.8 base image
FROM public.ecr.aws/lambda/python:3.8

ENV PIP_ROOT_USER_ACTION=ignore

# Install the dependencies
COPY requirements.txt .
RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"
# 降级到兼容GLIBC 2.26的Playwright版本
RUN pip3 install playwright==1.39.0 && playwright install --with-deps --target "${LAMBDA_TASK_ROOT}"

# Copy our function code
COPY handler.py ${LAMBDA_TASK_ROOT}
COPY new.py ${LAMBDA_TASK_ROOT}

# Set the handler function
CMD [ "handler.main" ]

方案2:升级Lambda Python版本

改用基于Amazon Linux 2023的Python镜像(如Python 3.11),该系统的GLIBC版本满足Playwright 1.45.0的要求:

# 改用Python 3.11镜像,基于Amazon Linux 2023,GLIBC版本达标
FROM public.ecr.aws/lambda/python:3.11

ENV PIP_ROOT_USER_ACTION=ignore

# Install the dependencies
COPY requirements.txt .
RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"
RUN pip3 install playwright==1.45.0 && playwright install --with-deps --target "${LAMBDA_TASK_ROOT}"

# Copy our function code
COPY handler.py ${LAMBDA_TASK_ROOT}
COPY new.py ${LAMBDA_TASK_ROOT}

# Set the handler function
CMD [ "handler.main" ]

方案对比

  • 方案1:无需改变Python环境,适合依赖Python 3.8的场景,但无法使用Playwright 1.40+的新特性。
  • 方案2:可保留最新Playwright功能,但需确认你的Python代码兼容3.11版本。

内容的提问来源于stack exchange,提问作者NESSMA HAMIDOU

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 12:23:20