logandk/serverless-wsgi

Feature request: ability to use serverless-wsgi with Docker containers in ECR with Django, Flask and other wsgi frameworks (solution inside)

ArtikUA opened this issue · 5 comments

Serverless supports containers: https://www.serverless.com/blog/container-support-for-lambda
It would be amazing if it would be possible to have the support of serverless-wsgi of it, for now it's asking:
'Unable to load virtualenv, please install\n'
even if everything (django and other dependencies) are installed in the image

It's easier than I thought:
https://github.com/pritul95/aws-lambda-container/tree/main/py_flask

The only difference that for django there should be another path to wsgi application

But still it would be nice to have this feature out of the box

The more convenient way to do it is just to put these lines in your Dockerfile:

COPY ./node_modules/serverless-wsgi/serverless_wsgi.py ./serverless_wsgi.py
COPY ./node_modules/serverless-wsgi/wsgi_handler.py ./wsgi_handler.py
RUN echo -e '{"app": "app.wsgi.application"}' > .serverless-wsgi

Or to put these lines to your CI/CD tool (better way):

cp ./node_modules/serverless-wsgi/serverless_wsgi.py ./serverless_wsgi.py
cp ./node_modules/serverless-wsgi/wsgi_handler.py ./wsgi_handler.py
echo -e '{"app": "app.wsgi.application"}' > .serverless-wsgi

Of course, you need to change app.wsgi.application to the path to your wsgi handler

I agree, it would be awesome to have a nice Docker integration built-in. Happy to accept a PR for this.

+1
Is there a simple way to do it ? I am blocked by the size of the package. That's why I would like to use a docker container to have a possible disk size of 10 GB.

The more convenient way to do it is just to put these lines in your Dockerfile:

COPY ./node_modules/serverless-wsgi/serverless_wsgi.py ./serverless_wsgi.py
COPY ./node_modules/serverless-wsgi/wsgi_handler.py ./wsgi_handler.py
RUN echo -e '{"app": "app.wsgi.application"}' > .serverless-wsgi

Or to put these lines to your CI/CD tool (better way):

cp ./node_modules/serverless-wsgi/serverless_wsgi.py ./serverless_wsgi.py
cp ./node_modules/serverless-wsgi/wsgi_handler.py ./wsgi_handler.py
echo -e '{"app": "app.wsgi.application"}' > .serverless-wsgi

Of course, you need to change app.wsgi.application to the path to your wsgi handler

Can you show us the content of your serverless file? Thank you.