aws / aws-lambda-runtime-interface-emulator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

curl: (52) Empty reply from server

momotaro98 opened this issue · comments

Env

MacOS: 10.15.7
Docker on Mac: Version 18.06.1-ce-mac73 (26764).
Docker Engin: Engine: 18.06.1-ce

Premise

Dockerfile

FROM public.ecr.aws/lambda/provided:al2
COPY bin/search_tutor /search_tutor
ENTRYPOINT [ "/search_tutor" ]

search_tutor is just a binary file built by Golang.

The app Lambda is for API Gateway integration and has the same structure with https://docs.aws.amazon.com/lambda/latest/dg/golang-handler.html

docker build -t myfunction:latest .
docker run -p 9000:8080 --env-file ./env.list myfunction:latest
$ docker ps
94685e614c95        myfunction:latest                                     "/search_tutor"          8 minutes ago       Up 8 minutes        0.0.0.0:9000->8080/tcp             myfunction

I confirmed Go app initialization is finished. Also, it seems Go app is listening for requests.

Problem

When I call the docker from my local of RIE like below.

curl -XPOST "http://localhost:9000/215-03-31/functns/function/invocations" -d '{}'

I'm getting the following error.

curl: (52) Empty reply from server

I understand it's network issue between host and the docker container but I don't know the root cause and how to debug.

Sorry my bad. I could fix this issue by doing followings.

fix Dockerfile

FROM alpine
COPY bin/search_tutor /search_tutor
# ENTRYPOINT [ "/search_tutor" ]
ADD https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie /usr/bin/aws-lambda-rie
RUN chmod 755 /usr/bin/aws-lambda-rie
COPY entry.sh /
RUN chmod 755 /entry.sh
ENTRYPOINT [ "/entry.sh" ]

add entry.sh

#!/bin/sh
if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then
  exec /usr/bin/aws-lambda-rie "$@"
else
  exec "$@"
fi

install rie command to local

mkdir -p ~/.aws-lambda-rie && curl -Lo ~/.aws-lambda-rie/aws-lambda-rie \
https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie \
&& chmod +x ~/.aws-lambda-rie/aws-lambda-rie

run docker with volume sync

docker run -v ~/.aws-lambda-rie:/aws-lambda --entrypoint /aws-lambda/aws-lambda-rie -p 9000:8080 --env-file ./env.list --name myfunction myfunction:latest /search_tutor