2

I want to make a Google Cloud Function with HTTP trigger that call another function (example: changeString). I know that I can include the function changeString in index.js. However, I want to reuse changeString so others Google Cloud Functions can call it.

exports.helloWorld = function helloWorld(req, res) {
var result = changeString(req.body.string);
res.send(result);
};

I know that there is a similar question, but it did not solve my problem.

CSDD
  • 339
  • 2
  • 14
  • Basically, I just want to know the syntax to call a function from another function in Google Cloud Function. – CSDD Jul 14 '17 at 12:01

2 Answers2

0

I was wondering about this myself and I think the answer is that you don’t call the function. Instead, you should send a payload to the PubSub service from your HTTP Cloud Function. A secondary Cloud Function subscribes to the PubSub topic and consumes the payload (which is Base64 encoded).

-1

As @user3158158 brings out, you would publish a message to a Pub/Sub service. This is highlighted here: https://cloud.google.com/functions/docs/calling/pubsub#publishing_a_message_from_within_a_function

I shows the sample syntax at the above link, I needed to do the same thing today.