aws / aws/aws-lambda-base-images

Can't invoke Python 3.7 image locally

Open
#23 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
No language data
Stars
777
Forks
118
PR merge metrics
No merged PRs in 30d

Description

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:

```python
def main(event, context):
print(event)
print()
print(context)

if __name__ == '__main__':
event = 'testing'
context = '123'
main(event, context)
```

2. Create Dockerfile:

```dockerfile
FROM amazon/aws-lambda-python:3.7
COPY app.py ${LAMBDA_TASK_ROOT}
CMD ["app.main"]
```

3. Build container:

```shell
docker build -t local-lambda-test .
```

4. Start the container in one shell:

```shell
docker run -p 9000:8080 local-lambda-test:latest
```

5. In another shell, send the container the same test payload from the docs:

```shell
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](https://user-images.githubusercontent.com/86746490/134391677-2480245f-20b0-4c34-bec4-4ce54e005046.png)

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

![image](https://user-images.githubusercontent.com/86746490/134391892-dc6ca4c0-0827-4645-beae-63bd6dfac593.png)

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

![image](https://user-images.githubusercontent.com/86746490/134392153-e7199504-15fc-43b1-93b6-88f7f3fd9fd3.png)

---

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!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.