Access Google Cloud resources from Python Cloud Function (YouTube tutorial)

Accessing Google Cloud resources manually is straightforward. We can use the Web UI or the SDK in the console. However, when we try to the same thing programmatically, from the context of a local script or a cloud function, we run into authorization problems.

In this YouTube tutorial we are writing a cloud function that accesses the Notebooks API in Google Clouds. We are using Python 3 for writing the function.

requirements.txt

google-api-python-client

main.py

from googleapiclient import discovery

def hello_world(request):
    notebooks = discovery.build("notebooks", "v1")
    response = notebooks.projects().locations().instances().list(parent="projects/vladsave-llc/locations/us-central1-a").execute()
    return response

Leave a comment

Your email address will not be published. Required fields are marked *