[英]Lambda times out when testing locally
I'm testing an AWS Lambda function locally, but my container hits a timeout after 300 seconds.我正在本地测试 AWS Lambda function,但我的容器在 300 秒后超时。 I've been doing some research and have already read some AWS documents about this , besides this document I also read other StackOverflow questions .我一直在做一些研究并且已经阅读了一些关于这个的 AWS 文档,除了这个文档之外我还阅读了其他 StackOverflow 问题。
I'm developing with Python and use Sentry to get telemetry about my function. When building the container to test things locally I use the following Dockerfile:我正在使用 Python 进行开发,并使用Sentry获取有关我的 function 的遥测数据。在构建容器以在本地进行测试时,我使用以下 Dockerfile:
FROM public.ecr.aws/lambda/python:3.8
# Install the function's dependencies using file requirements.txt
# from your project folder.
COPY requirements.txt .
RUN pip install --upgrade pip -q
RUN pip install wheel
RUN pip install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"
# Copy function code
COPY main.py ${LAMBDA_TASK_ROOT}
COPY misc/* ./misc/
COPY sql/* ./sql/
# Set the CMD to your handler (could be done as a parameter override)
CMD [ "main.lambda_handler" ]
And I create my API requests through Postman. Based on this I already checked if the timeout was originating in Postman or Sentry, but timeout settings in these tools are set above the 300 second timeout I'm getting.我通过 Postman 创建我的 API 请求。基于此,我已经检查了超时是否源自 Postman 或 Sentry,但这些工具中的超时设置高于我得到的 300 秒超时。 I've come to believe the timeout could be coming from the Docker image I'm using , but haven't found information about this online.我开始相信超时可能来自我正在使用的 Docker 图像,但尚未在网上找到有关此信息。 To manage AWS related things in the code I import the boto3 library and also suspect the setting I'm looking for could be related to this library.为了在代码中管理 AWS 相关的东西,我导入了boto3 库,并且还怀疑我正在寻找的设置可能与这个库有关。
The lambda that's in production already has a timeout set to the 15-minute max allowed by AWS, but when testing locally the problem appears.生产中的 lambda 已经将超时设置为 AWS 允许的 15 分钟最大值,但在本地测试时出现问题。 I've also checked if the Access Keys I'm using to execute things locally have a timeout, but haven't found anything pointing in this direction.我还检查了我用来在本地执行操作的访问密钥是否有超时,但没有发现任何指向这个方向的东西。
I'm new to developing on AWS Lambda services so this might be some very basic stuff, thank you!我刚开始开发 AWS Lambda 服务,所以这可能是一些非常基本的东西,谢谢!
Your guess is correct.你的猜测是正确的。 There is a default timeout in AWS Lambda Runtime Interface Emulator and it is 300 seconds. AWS Lambda Runtime Interface Emulator 中有一个默认超时,它是 300 秒。 See its repo on GitHub. And specific line that shows it.在 GitHub 上查看它的repo 。以及显示它的特定行。
If you need to increase it, you'll have to pass it as ENV variable to docker.如果你需要增加它,你必须将它作为 ENV 变量传递给 docker。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.