Call Cloud function from within Cloud Function

Hi Team,

I looked through the documentation and didn’t see anything but I was able to come up with a solution. I have tested this and it works. I want to know if this the proper and best way to call a cloud function from within a cloud function.

// This is the target function
Moralis.Cloud.define("getBob", async (request) => {
return {"name":"Bob Roberts"};
});

// This function is meant to call the target.                     
Moralis.Cloud.define("getIt",async(request) => {
 return await Moralis.Cloud.run("getBob");
});

Thank you,

David

3 Likes

You can run CF like this

2 Likes

@ivan,

Thank you, so the example solution I provided above is the best way to perform inter cloud function call.

Any idea of how cost model will price this?

  • As two separate function calls?
  • As one function call but combine CPU/RAM use?
    -or ???

Working on an idea for a REST API to call via ChainLink. It will need to do some data aggregation and follow a rule tree so a few internal function calls will be required for a single get.

Thank you,

David

Hi,

Our mission is to make this infrastructure available to as many developers as possible. No matter the budget, you can use Moralis to build your dapp and go to market quickly. Therefore Moralis will always have a very generous free plan. Exact pricing and pricing models for dapps requiring bigger infrastructure will be released in the coming weeks.We will let you know all the details then. Thank you. :slight_smile:

2 Likes

It’s possible to define functions and constants outside the Moralis.Cloud.define() calls. So this is also possible:

const HIS_NAME = "Robert Paulson";

function getPerson(name) {
  return { name };
}

Moralis.Cloud.define("getBob", async (request) => {
  return getPerson(HIS_NAME);
});

// This function is meant to call the target.                     
Moralis.Cloud.define("getIt",async(request) => {
 return getPerson("it");
});
5 Likes

Very cool, thank you!