Reputation: 299
PS: I was doing it synchronously by using the following in my cloud function:
name = "projects/project1/locations/us-central1/functions/test3"
body = {
'data': '{ "message": "Function Invoked Successfully"}'
}
result = self.google_api_service.projects().locations().functions().call(name=name, body=body).execute()
#google_api_service has it's own functions
print(result)
Help me out to do it asynchronously! Also please do not suggest Pub/Sub. Is there any other workaround in python?
Upvotes: 2
Views: 1622
Reputation: 5819
There are two parts to answer your question:
Grant the Cloud Functions Invoker (
roles/cloudfunctions.invoker
) role to the calling function identity on the receiving function. By default, this identity is[email protected]
And then in the calling function you have to:
- Create a Google-signed OAuth ID token with the audience (
aud
) set to the URL of the receiving function.- Include the ID token in an
Authorization: Bearer ID_TOKEN
header in the request to the function.
NOTE: You can follow the code example in the same documentation link on how to include it.
import multiprocessing
import requests
p = multiprocessing.Pool(processes = 1)
p.apply_async(requests.get, ['YOUR_FUNCTION_URL'])
Upvotes: 1