Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zappa with docker and pipenv not working #1253

Closed
LeonardoFurtado opened this issue May 30, 2023 · 7 comments
Closed

Zappa with docker and pipenv not working #1253

LeonardoFurtado opened this issue May 30, 2023 · 7 comments
Labels
auto-closed [Bot] Closed, details in comments no-activity [Bot] Closing soon if no new activity

Comments

@LeonardoFurtado
Copy link

Context

I am trying to use zappa with docker and pipenv, i followed the link on readme to https://ianwhitestone.work/zappa-serverless-docker/ and tried all steps, but there is a line that shows a change we need to do in dockerfile to work with pipenv:

Note, if you’re pipenv instead of poetry, you can run: pip install pipenv && pipenv install. Or if you have a requirements.txt, you can run: RUN pip install -r requirements.txt.

But it doesn't work. If you do it you will receive a zappa not found after run docker build.

So I tried to create my own Dockerfile with some changes and this is what I'm using:

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"]

but it is not working...

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

Expected Behavior

Run application on docker with zappa setup to lambda

Actual Behavior

broken

Possible Fix

change dockerfile suggested

I already created a repo with the code used on tutorial linked on zappa readme with the dockerfile changed: https://github.com/LeonardoFurtado/zappa-docker

@kyaryunha
Copy link
Contributor

kyaryunha commented May 31, 2023

Are you run a RUN zappa save-python-settings-file ${STAGE_NAME} ?

This command changes the zappa_settings.json file to py.
You can write it inside the dockerfile, or you can move the py after running it outside the dockerfile.

I don't know exactly, but I've seen that error before, and I think I solved it by writing that sentence.
It's not written in the zappa readme, but it's a command written on ianwhitestone(maybe zappa contributer)'s blog.

@souravjamwal77
Copy link
Collaborator

Hi @LeonardoFurtado
@kyaryunha is correct, the blog post he is talking about is here . Please refer to this blog post or you can join Zappa's official channel here. The link will expire in 14 days.

@kyaryunha
Copy link
Contributor

How about adding something about save-python-settings-file to README.md?
Even if the ianwhitestone blog pops up right away when we search, people may not know because there is no explanation in README.md.
I don't know what exactly the save-python-settings-file is for, so I can not write about that.
Could someone who knows better write it?

@LeonardoFurtado
Copy link
Author

@kyaryunha the problem was not with save-python-settings-file, this step was done by me. I can't add the solution now, but I'll try to reply here later today. It's related to the way he suggested to use pipenv.

@joelwebb
Copy link

joelwebb commented Jan 3, 2024

Are there any updates on this? We spent the better part of yesterday troubleshooting the same issue, but trying to work with python 3.11 instead of 3.8. Following Ian's blog mentioned above we couldn't get this method to work with flask but could run basic python scripts using the lambda handler, but never get the flask apps to work correctly. @LeonardoFurtado do you have updates to this repo with the solution by chance?

Copy link

github-actions bot commented Apr 3, 2024

Hi there! Unfortunately, this Issue has not seen any activity for at least 90 days. If the Issue is still relevant to the latest version of Zappa, please comment within the next 10 days if you wish to keep it open. Otherwise, it will be automatically closed.

@github-actions github-actions bot added the no-activity [Bot] Closing soon if no new activity label Apr 3, 2024
Copy link

Hi there! Unfortunately, this Issue was automatically closed as it had not seen any activity in at least 100 days. If the Issue is still relevant to the latest version of Zappa, please open a new Issue.

@github-actions github-actions bot added the auto-closed [Bot] Closed, details in comments label Apr 13, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-closed [Bot] Closed, details in comments no-activity [Bot] Closing soon if no new activity
Projects
None yet
Development

No branches or pull requests

4 participants