为 Lambda 函数使用容器镜像
Using container image for Lamda function
我想在本地测试一个非常简单的 Lambda 函数。
app.py
def lambda_handler(event, context):
return "hello"
Docker 文件
FROM public.ecr.aws/lambda/python:3.8
COPY app.py .
CMD [ "app.lambda_handler" ]
在我使用
构建图像之后
docker build -t hello-world-3 .
我不能 运行 在本地:
docker run -p 9000:8080 -it hello-world-3
[INFO] (rapid) exec '/var/runtime/bootstrap' (cwd=/var/task, handler=)
如何在本地调用我的图像?它 运行 作为 AWS 上的 Lambda 函数没问题。
使用 hello-world-3
图像启动容器后,您只需 运行 来自主机(在另一个终端上)的 curl
命令来访问暴露的特定端点:
curl -X POST http://localhost:9000/2015-03-31/functions/function/invocations -d '{}'
您可以在此处的文档末尾找到它:https://hub.docker.com/r/amazon/aws-lambda-python, or also there : https://docs.aws.amazon.com/lambda/latest/dg/images-test.html#images-test-AWSbase。
调用您的容器后,您应该会在启动该容器的终端中看到您的请求。例如:
START RequestId: da204eb4-7ff2-4382-85fb-44a01166194b Version: $LATEST
END RequestId: da204eb4-7ff2-4382-85fb-44a01166194b
REPORT RequestId: da204eb4-7ff2-4382-85fb-44a01166194b Duration: 0.71 ms Billed Duration: 1 ms Memory Size: 3008 MB Max Memory Used: 3008 MB
我想在本地测试一个非常简单的 Lambda 函数。
app.py
def lambda_handler(event, context):
return "hello"
Docker 文件
FROM public.ecr.aws/lambda/python:3.8
COPY app.py .
CMD [ "app.lambda_handler" ]
在我使用
构建图像之后docker build -t hello-world-3 .
我不能 运行 在本地:
docker run -p 9000:8080 -it hello-world-3
[INFO] (rapid) exec '/var/runtime/bootstrap' (cwd=/var/task, handler=)
如何在本地调用我的图像?它 运行 作为 AWS 上的 Lambda 函数没问题。
使用 hello-world-3
图像启动容器后,您只需 运行 来自主机(在另一个终端上)的 curl
命令来访问暴露的特定端点:
curl -X POST http://localhost:9000/2015-03-31/functions/function/invocations -d '{}'
您可以在此处的文档末尾找到它:https://hub.docker.com/r/amazon/aws-lambda-python, or also there : https://docs.aws.amazon.com/lambda/latest/dg/images-test.html#images-test-AWSbase。
调用您的容器后,您应该会在启动该容器的终端中看到您的请求。例如:
START RequestId: da204eb4-7ff2-4382-85fb-44a01166194b Version: $LATEST
END RequestId: da204eb4-7ff2-4382-85fb-44a01166194b
REPORT RequestId: da204eb4-7ff2-4382-85fb-44a01166194b Duration: 0.71 ms Billed Duration: 1 ms Memory Size: 3008 MB Max Memory Used: 3008 MB