Search code examples
pythonamazon-web-servicesdockeraws-lambda

Docker image giving Timeout after 300 seconds


I am testing a AWS lambda docker image on Local computer and if the process is under 5min/300 sec, it runs smoothly, and if the time limit approaches 300 sec, it gives timeout error. I haven't set any time limit anywhere. Here's my docker script:

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"]

And here's the timeout error:

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 

Solution

  • For testing on local, pass in the env variable AWS_LAMBDA_FUNCTION_TIMEOUT, in the docker file. For example, to set the docker time out of 10 min,

    ENV AWS_LAMBDA_FUNCTION_TIMEOUT="600"
    

    After this, built the docker image again and run it.