Hello.
I'm taking my first steps with cloud functions (1 gen) http trigger and I'm having problems calling my functions using the nodejs @google-cloud/functions lib.
I'm making the calls using the CloudFunctionsServiceClient's callFunction method, however, after a few successful calls I start to receive an error due to the function test quota overflow.
Researching I discovered that the callFunctions method should not be used in production but I couldn't find out how to make calls without using this method.
My code is like this below
const name = 'abc123'
const data = 'abc123'
const {CloudFunctionsServiceClient} = require('@google-cloud/functions').v1;
const functionsClient = new CloudFunctionsServiceClient();
async function callCallFunction() {
const request = {
name,
data,
};
const response = await functionsClient.callFunction(request);
console.log(response);
}
callCallFunction();
I would be very grateful if you could help me with this.
As shown in the quickstart Create and deploy a HTTP Cloud Function by using Node.js, in section Testing the function, you can get the https trigger url as follows:
When the function finishes deploying, take note of the httpsTrigger.url property or find it using the following command:
gcloud functions describe functionName
It should look like this:
https://GCP_REGION-PROJECT_ID.cloudfunctions.net/helloHttp
Then, with that url you can call your function with Postman as shown on this answer on Stack Overflow:
Another way is to call your function from the console, as shown in the documentation:
Finally, for debugging purposes, you could also call your function directly using the Google Cloud CLI:
To directly invoke a function using the gcloud CLI, use the gcloud functions call command and supply any data your function expects as JSON in the --data argument. For example:
gcloud functions call YOUR_FUNCTION_NAME --data '{"name":"Keyboard Cat"}'
See also: