Python Google Cloud Functions have been introduced publically in Q3-Q4 2018.
Deploying them takes time (2-10 minutes with gcloud functions deploy
.
Actually, a Python cloud function equates to a Flask handler.
Thus, you can test them cloud function first on your own computer.
This spares you from long deployments, difficult step-by-step debugging and bad GCP weather.
Here is how:
- keep the traditional Python Cloud Function
requirements.txt
andmain.py
untouched. - add
emulator-requirements.txt
(a super-set combining aflask
module + therequirements.txt
's contents) - add
emulator.py
- leave any Python virtual environment and make one out of
emulator-requirements.txt
- Example:
mkvirtualenv my_function_emulator -p /usr/bin/python3.6; workon my_function emulator
- then:
pip install -r emulator-requirements.txt
- run
python emulator.py
within that new virtual environment - keep the Flask server running, then test it by running
sh local_curl_tests.sh
- kill your Flask server
(Ctrl+C in the emulator.py window)
- deploy your Cloud Function using
sh deploy.sh
- test it using
sh remote_curl_tests.sh
- You are a super star!! Tap yourself on the shoulder : )