Cloud function call from another cloud function

I use Cloud Function to call another cloud function at a free spark level.

Is there a special way to call another cloud function? Or are you just using a standard HTTP request?

I tried calling another function directly like this:

exports.purchaseTicket = functions.https.onRequest((req, res) => { fetch('https://us-central1-functions-****.cloudfunctions.net/validate') .then(response => response.json()) .then(json => res.status(201).json(json)) }) 

But I get an error

FetchError: request https: // us-central1-functions- ****. cloudfunctions.net/validate failed, reason: getaddrinfo ENOTFOUND us-central1-functions - ***** cloudfunctions.net. us-central1-functions -. ***** cloudfunctions.net:443

It looks like firebase is blocking the connection, even though it belongs to Google, and therefore it should not be blocked

Spark's plan only allows outgoing network requests to Google-owned services.

How can I use Cloud Function to call another Cloud function?

+20
javascript firebase google-cloud-functions
source share
2 answers

You do not need to worry about calling some common functions with an all new HTTPS call. You can simply abstract the regular bits of code into a regular javascript function that is called by one of them. For example, you can modify the helloWorld template, for example:

 var functions = require('firebase-functions'); exports.helloWorld = functions.https.onRequest((request, response) => { common(response) }) exports.helloWorld2 = functions.https.onRequest((request, response) => { common(response) }) function common(response) { response.send("Hello from a regular old function!"); } 

These two functions will do the same, but with different endpoints.

+14
source share

I am using Python for a cloud function. How to call a cloud function from another cloud function using python. I can not add a comment to the answer above, since I do not have 50 reputation yet. So please ask here

0
source share

All Articles