Cloud Functions calling each other

711 views
Skip to first unread message

parth jangid

unread,
Aug 3, 2023, 11:35:38 PM8/3/23
to Firebase Google Group
Greetings,
I have a. simple doubt, I am not able to deploy my functions using firebase deploy --only functions so I am using gcloud and then functions are being deploy and are visible in firebase console too.

But I have a question that I have deployed a JS function (let's say jsFunc.js) and I have another Python function (let's say pyFunc.py). Now, inside of jsFunc.js I am using the url of Python Function and calling it but as both the functions require authentication jsFunc.js is not able to call pyFunc.py and hence I get 403 error. 

So, I made the pyFunc.py public and it works.

When I am calling jsFunc.js from Postman, I am passing a bearer token hence it works now as pyFunc.py is public hence jsFunc.js is able to call it.

So can someone help me what is the correct way to call pyFunc.py from jsFunc.js, while ensuring both functions are not public?

Also on whole another note, if my user successfully signs in the application using google account then any call to jsFunc.js made by the this authenticated user will not result in  any 400 level error right?

Jeff Huleatt

unread,
Aug 4, 2023, 2:56:51 PM8/4/23
to Firebase Google Group
Hi Parth, 

Functions can call each other with custom event triggers: https://firebase.google.com/docs/functions/custom-events. If, like in your example, jsFunc is calling pyFunc, then you'd follow the Publish an event to a channel instructions in jsFunc, and follow Handle custom events for pyFunc. If you aren't able to use the Firebase CLI and Cloud Functions for Firebase SDKs, you could follow the Google Cloud docs for Eventarc triggers instead (that's what custom events in Cloud Functions for Firebase use under the hood).

For your second question, it depends if you're using callable functions or plain https triggers. Callable functions are called with the client side Firebase SDK, which automatically includes Auth context on every call. For https triggers, it's up to you to include auth information (usually in the Bearer token as you mentioned) when you call the function, and to validate the auth information in your function. In addition, the Firebase CLI sets https triggers to be open to the public by default, but the gcloud CLI may not. If your https function is rejecting requests unexpectedly, try following Allowing unauthenticated HTTP function invocation from the Cloud docs.

Best,
Jeff

parth jangid

unread,
Aug 4, 2023, 7:32:02 PM8/4/23
to Firebase Google Group
Hey Jeff,
Thank you so much for such an elaborate answer, Now I do understand it very well. I am planning to make function's trigger to Callable rather than HTTP. That seems to be a better idea in general.

Thanks a ton again!

Reply all
Reply to author
Forward
0 new messages