I'm trying to deploy a simple hello-world AWS lambda function as a container image. I'm at the stage of testing the function following the instructions found here: https://docs.aws.amazon.com/lambda/latest/dg/images-test.html.
However, I'm not able to trigger the function using the built-in RIE. I must be missing something very basic. Here are the details:
Handler code (app.py):
def handler(event, context):
return 'Hello from AWS Lambda using Python'
Dockerfile:
FROM public.ecr.aws/lambda/python:3.8
COPY app.py ./
CMD ["app.handler"]
Docker build:
(venv) test % docker build -t mytest:latest .
[+] Building 0.9s (7/7) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 36B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for public.ecr.aws/lambda/python:3.8 0.8s
=> [internal] load build context 0.0s
=> => transferring context: 27B 0.0s
=> [1/2] FROM public.ecr.aws/lambda/python:3.8@sha256:086ab31133d855f5a935ae3cf6f592cad416a7415cdb7a3f0b25f5e15b7d4ea5 0.0s
=> => resolve public.ecr.aws/lambda/python:3.8@sha256:086ab31133d855f5a935ae3cf6f592cad416a7415cdb7a3f0b25f5e15b7d4ea5 0.0s
=> CACHED [2/2] COPY app.py ./ 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:c90a438594cad5f940b78986f91e8c135a50f68a1bc0c17201a02a67edc1cfff 0.0s
=> => naming to docker.io/library/mytest:latest 0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
(venv) test %
Docker run:
(venv) test % docker run -p 9000:8080 mytest:latest
22 May 2022 20:55:34,516 [INFO] (rapid) exec '/var/runtime/bootstrap' (cwd=/var/task, handler=)
Attempt to trigger the handler:
~ % curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}' --http0.9 --output - -v
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying 127.0.0.1:9000...
* Connected to localhost (127.0.0.1) port 9000 (#0)
> POST /2015-03-31/functions/function/invocations HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Length: 2
> Content-Type: application/x-www-form-urlencoded
>
* Closing connection 0
At this point the HTTP request just hangs until it eventually times out. There is no output on the docker container console either.
My docker runtime (MacOS 12.3.1):
(venv) test % docker --version
Docker version 20.10.11, build dea9396
(venv) test %