aws / aws-lambda-base-images

Apache License 2.0
670 stars 110 forks source link

Can't invoke Python 3.7 image locally #23

Open jackcan2 opened 3 years ago

jackcan2 commented 3 years ago

I'm trying to deploy a function and am having issues testing locally (on a linux server) as described in the docs:

https://docs.aws.amazon.com/lambda/latest/dg/images-test.html#images-test-AWSbase https://hub.docker.com/r/amazon/aws-lambda-python

Here are the steps to reproduce, using a simple Python app:

  1. Create app.py:
def main(event, context):
    print(event)
    print()
    print(context)

if __name__ == '__main__':
    event = 'testing'
    context = '123'
    main(event, context)
  1. Create Dockerfile:
FROM amazon/aws-lambda-python:3.7
COPY app.py ${LAMBDA_TASK_ROOT}
CMD ["app.main"]
  1. Build container:
docker build -t local-lambda-test .
  1. Start the container in one shell:
docker run -p 9000:8080 local-lambda-test:latest
  1. In another shell, send the container the same test payload from the docs:
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"payload":"hello world!"}'

I expect to see the container logs print the payload and context, but instead I get a bad response and the container does nothing.


Here is what happens on my end after I start the container as in step 4 above:

  1. I run docker run -p 9000:8080 local-lambda-test:latest and get the following output:

image

  1. Verify connection with telnet to rule out connection issues:

image

  1. Send payload to the container and get an error in the response:

image


For the love of all that is holy, does anyone know what's going on here?! Have any of you seen this problem before, or have an idea of where I might be going wrong?

Thanks!

justinmk3 commented 3 years ago

I ran your steps exactly, here's what I see:

$ docker run -p 9000:8080 local-lambda-test:latest
time="2021-09-22T22:24:05.372" level=info msg="exec '/var/runtime/bootstrap' (cwd=/var/task, handler=)"
time="2021-09-22T22:24:27.366" level=info msg="extensionsDisabledByLayer(/opt/disable-extensions-jwigqn8j) -> stat /opt/disable-extensions-jwigqn8j: no such file or directory"
time="2021-09-22T22:24:27.366" level=warning msg="Cannot list external agents" error="open /opt/extensions: no such file or directory"
START RequestId: 1b21fcb0-53cb-4778-a9e3-b6c238b98ad7 Version: $LATEST
{'payload': 'hello world!'}

have an idea of where I might be going wrong?

Maybe local networking / iptables configuration ?

jackcan2 commented 3 years ago

Thanks @justinmk3 - if you're not able to duplicate the issue then I'll dig in and see if I can find any networking issues.

massimo-camplani-kidsloop commented 2 years ago

Has this been solved? I have the same issue, just running the example explained here

https://docs.aws.amazon.com/lambda/latest/dg/python-image.html

But with PYTHON 3.7 or 3.6 I got no response and an error due to glibc

Screenshot 2022-03-16 at 13 56 07

It is basically not possible to run aws-lambda with python versions older than 3.8. I thought it was my code or dependencies generating the issue, but not it is vanilla image with no code

Any suggestions?