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

本地测试AWS Lambda Docker镜像遇300秒超时问题求助

AWS Lambda Docker镜像本地测试触发300秒超时问题排查

问题描述

本地测试AWS Lambda Docker镜像时,处理时长在5分钟(300秒)以内运行正常,接近300秒就触发超时错误,且未手动设置任何时间限制。

我的Dockerfile

FROM public.ecr.aws/lambda/python:3.9
ENV GOOGLE_APPLICATION_CREDENTIALS cloud_vision_api/vision-api.json


RUN yum install git -y
RUN yum update -y && yum install amazon-linux-extras -y && PYTHON=python2 amazon-linux-extras install epel -y && yum update -y && yum install git-lfs -y
RUN git lfs install

COPY requirements.txt .
RUN pip3 install -r requirements.txt

COPY . .

CMD [ "handler.handle_response"]

超时错误日志

25 Oct 2023 05:56:18,129 [WARNING] (rapid) Reset initiated: Timeout
25 Oct 2023 05:56:18,130 [INFO] (rapid) Sending SIGKILL to runtime-1(14).
25 Oct 2023 05:56:18,155 [INFO] (rapid) Stopping runtime domain
25 Oct 2023 05:56:18,155 [INFO] (rapid) Waiting for runtime domain processes termination
25 Oct 2023 05:56:18,155 [INFO] (rapid) Stopping operator domain
25 Oct 2023 05:56:18,155 [INFO] (rapid) Starting runtime domain
END RequestId: 9501e4ef-f121-4385-9345-30e27825b70b
REPORT RequestId: 9501e4ef-f121-4385-9345-30e27825b70b  Duration: 300000.00 ms  Billed Duration: 300000 ms      Memory Size: 3008 MB    Max Memory Used: 3008 MB 

问题原因与解决方法

原因

AWS Lambda runtime的默认超时时间就是300秒,这是内置的默认配置,不管使用官方基础镜像还是自定义镜像,只要基于Lambda runtime运行,都会自动继承这个限制,哪怕未手动设置超时参数。

解决办法

本地测试时,通过设置环境变量AWS_LAMBDA_FUNCTION_TIMEOUT即可覆盖默认值,比如设置为Lambda允许的最大超时时间15分钟(900秒):

  • 使用docker run启动镜像时添加参数:
    docker run -e AWS_LAMBDA_FUNCTION_TIMEOUT=900 your-image-tag
    
  • 或者直接在Dockerfile中添加环境变量:
    ENV AWS_LAMBDA_FUNCTION_TIMEOUT=900
    

注意:Lambda的最大超时限制为900秒(15分钟),设置超过这个值也会被自动限制为900秒。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 21:38:38