Reputation: 41
I have written a Google Cloud Function, in Python, that catches Pub/Sub messages from Billing when a GAE/GCE project exceeds a budget threshhold and then either disables Billing or stops a GCE instance. I have used the example code in the Google documentation. Using console logging I have managed to debug what I have written and it is working OK.
This is clearly not the way to debug Google Cloud Functions, it is tediously slow and requires repeated attempts to narrow down problems. My reading of the documentation indicates that I should be able to run the functions locally and use VCode and on-line debugging under Windows 10 and that there is also a Google production debugging tool that can be used to debug live running Cloud Functions. However, after much searching I cannot find YouTube videos or write-ups that I can understand that show me how to access either of these debugging tools. Also most of the information I have found is either not for Python or not for Windows 10.
My skill level is probably relatively low in this area but I can follow a cookbook approach if I can find one.
Can anyone recommend suitable videos or write-ups? Thanks.
Upvotes: 3
Views: 981
Reputation: 2612
On GCP the Cloud Debbugger for Python would be the natural debuuging tool, however is not supported for Cloud Functions.
As an alternative you can use the functions framework for Python which is an open source service as a function that will allow you to run the cloud functions locally.
Using this library you can test the cloud Pub/Sub Triggered functions you mentioned.
To install this please runnthe following command:
pip install functions-framework
Or by adding the following line to your requirements.txt
functions-framework==2.0.0
Finally to locally "deploy" the Cloud Function run:
functions-framework --target=FUNCTION_NAME
This will raise a webserver on your localhost on the address: http://localhost:8080/
Upvotes: 1