How can I use google cloud functions to schedule a python script that works with python 3.6?

Viewed 306

One of the dependencies in my python script works with python 3.6 - it doesn't work with python 3.7.

I'm trying to deploy it as an app in google app engine with a flexible environment (i'm struggling with it) BUT it would be so much easier if I could set it up as a cloud function and schedule it with cloud pub/sub & cloud scheduler.

So, is there a way for me to make my python 3.6 script work with cloud functions which has a python 3.7 runtime?

1 Answers

You can't use Python 3.6 with Cloud Functions as there is no Python 3.6 runtime (and there won't be).

Instead, you could use Cloud Run, as it will allow you to use any Python version for your runtime. For example, the following Dockerfile would run your app with Python 3.6:

FROM python:3.6-slim

ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./

RUN pip install Flask gunicorn

CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 app:app

You'd need to convert your script to an endpoint in a Flask app, but that's basically equivalent to converting it to a Cloud Function.

Related