I tried to use zappa docs to use Zappa with Docker. But the doc is outdated and not work.
There is a tutorial about how to use zappa with docker and a suggestions about how to use with pipenv that don't work too.
I tried to change the dockerfile to it:
FROM python:3.8 as base
# Setup env
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONFAULTHANDLER 1
FROM base AS python-deps
# Install pipenv and compilation dependencies
RUN pip install pipenv
RUN python -m pip install --upgrade pip
RUN apt-get update && apt-get install -y --no-install-recommends gcc
RUN apt-get install postgresql-client libjpeg-dev -y
RUN apt-get install gcc libc-dev musl-dev zlib1g zlib1g-dev -y
# Install python dependencies in /.venv
COPY Pipfile .
COPY Pipfile.lock .
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy
#RUN apk del .tmp-build-deps
FROM base AS runtime
# Copy virtual env from python-deps stage
COPY --from=python-deps /.venv /.venv
ENV PATH="/.venv/bin:$PATH"
COPY . .
ARG FUNCTION_DIR="/var/task/"
COPY ./ $FUNCTION_DIR
# Grab the zappa handler.py and put it in the working directory
RUN ZAPPA_HANDLER_PATH=$( \
python -c "from zappa import handler; print (handler.__file__)" \
) \
&& echo $ZAPPA_HANDLER_PATH \
&& cp $ZAPPA_HANDLER_PATH $FUNCTION_DIR
CMD ["handler.lambda_handler"]
and I use the command docker build -t lambda-docker-flask:latest . and It works fine, but when I try to run docker run -p 9000:8080 lambda-docker-flask:latest I received the following error:
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "handler.lambda_handler": executable file not found in $PATH: unknown.
ERRO[0000] error waiting for container:
I was googling a lot about docker and some insights was to change
CMD ["handler.lambda_handler"]
to
CMD handler.lambda_handler
But I receive a different error:
/bin/sh: 1: handler.lambda_handler: not found
I would like a suggestion about what I can do. The code is available here: https://github.com/LeonardoFurtado/zappa-docker
I think you have the incorrect base image; it should be
amazon/aws-lambda-python:3.8instead ofpython:3.8.