I have a very simple Lambda function that I'd like to test locally.
app.py
def lambda_handler(event, context):
return "hello"
Dockerfile
FROM public.ecr.aws/lambda/python:3.8
COPY app.py .
CMD [ "app.lambda_handler" ]
After I build my image with
docker build -t hello-world-3 .
I can't run it locally:
docker run -p 9000:8080 -it hello-world-3
[INFO] (rapid) exec '/var/runtime/bootstrap' (cwd=/var/task, handler=)
How can I invoke my image locally? It runs fine as Lambda function on AWS.
CodePudding user response:
Once you have started your container with hello-world-3 image, you can just run a curl command from your host (on another terminal) to access the specific endpoint exposed:
curl -X POST http://localhost:9000/2015-03-31/functions/function/invocations -d '{}'
You can find that at the end of the documentation here : 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.
After calling your container, you should see your request in the terminal where you launched that container. For example:
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
