我试图解决错误Traceback (most recent call last):andler 'handler' missing on module 'lambda_function'
我的理解是,我在Dockerfile中的CMD命令找不到该函数。然而,我相信我正确地遵循了guide。
我的一部分认为我错过了一些需要的指南之外的东西。我在Windows上使用WSL来运行docker build,docker run,以及curl请求来测试它。关于如何解决这个问题,有什么建议吗?
目录:
── project
├── lambda_function.py
├── Dockerfile
├── requirements.txt
字符串
Python代码:
import sys
def handler(event, context):
return 'Hello from AWS Lambda using Python' + sys.version + '!'
型
Dockerfile:
FROM public.ecr.aws/lambda/python:3.11
# Copy requirements.txt
COPY requirements.txt ${LAMBDA_TASK_ROOT}
# Install the specified packages
RUN pip install -r requirements.txt
# Copy function code
COPY lambda_function.py ${LAMBDA_TASK_ROOT}
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "lambda_function.handler" ]
型
命令测试docker build --platform linux/amd64 -t docker-image:test .
个docker run -p 9000:8080 docker-image:test
个
然后我打开一个新的终端与相同的目录curl "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"payload":"hello world!"}'
个
curl请求错误:{"errorMessage": "Handler 'handler' missing on module 'lambda_function'", "errorType": "Runtime.HandlerNotFound", "requestId": "f76bd6cb-e91e-4197-842c-d8ae0c077a65", "stackTrace": []}
个
START RequestId: 0598dfd5-bd4d-406f-8c9d-d61ef4dffee4 Version: $LATEST
28 Oct 2023 17:03:02,249 [INFO] (rapid) extensionsDisabledByLayer(/opt/disable-extensions-jwigqn8j) -> stat /opt/disable-extensions-jwigqn8j: no such file or directory
28 Oct 2023 17:03:02,249 [INFO] (rapid) Configuring and starting Operator Domain
28 Oct 2023 17:03:02,249 [INFO] (rapid) Starting runtime domain
28 Oct 2023 17:03:02,249 [WARNING] (rapid) Cannot list external agents error=open /opt/extensions: no such file or directory
28 Oct 2023 17:03:02,249 [INFO] (rapid) Starting runtime without AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN , Expected?: false
Traceback (most recent call last):andler 'handler' missing on module 'lambda_function'
END RequestId: f76bd6cb-e91e-4197-842c-d8ae0c077a65
REPORT RequestId: f76bd6cb-e91e-4197-842c-d8ae0c077a65 Init Duration: 0.08 ms Duration: 59.60 ms Billed Duration: 60 ms Memory Size: 3008 MB Max Memory Used: 3008 MB
型
1条答案
按热度按时间polkgigr1#
Python文件lambda_function.py未保存,因此它使用了一个空白的lambda_function.py文件,并且由于无法在其中找到预期的函数而失败