Using netlify functions with gatsby cloud (Example)

Hi team,
since my netlify builds broke with the memory issue starting after gatsby v4.7.2, i had to move to gatsby cloud, keeping hosting at netlify. The builds work fine, but im trying for 9 days now to get the netlify-functions work without success.

After successfully building in gatsby cloud i get following error in deploying to netlify without more details (local “netlify deploy” works):

That’s my test function hello.js in /netlify/functions/

My netlify.toml (as described in Option 2 here: https://support.gatsbyjs.com/hc/en-us/articles/360054529274-Deploying-Netlify-Functions-from-Gatsby-Cloud):

[build]
    #gatsby cloud build netlify functions
    functions="public/functions"

and my postbuild in gatsby-node.js:

exports.onPostBuild = async (gatsbyNodeHelpers) => {
  const { reporter } = gatsbyNodeHelpers;

  const reportOut = (report) => {
    const { stderr, stdout } = report;
    if (stderr) reporter.error(stderr);
    if (stdout) reporter.info(stdout);
  };

  reportOut(await exec("yarn lambda"));
};

package.json

"scripts": {
    "lambda": "netlify-lambda build netlify/functions/"
  },
plugins: [
    "gatsby-plugin-gatsby-cloud",
    "gatsby-plugin-netlify",
],

So the idea is, gatsby builds the website, onPostBuild builds the functions, copies into /public/functions and in deploying (which is for me the blackbox) the functions gets behind the scene zipped and shipped to AWS.

My “advanced” functions are not static and using dependencies, that’s why i use neltify-lambda with global packages.

I feel like of many changes in the documentation, it’s not very clear how to implement netlify-functions in external CI. Sometimes the default functions path is /src/functions, /functions, /netlify/functions, /static, … And it’s hard to understand what happens out of the box.

I’m looking forward for any help, thank you in advance! A working and latest example would be more than enough.
Tobias

“siteId”: “022b00b8-d1d6-4e0d-809a-7d3a28169c8a”

Hi @NovelNet,

netlify-lambda is a rather old package and I won’t recommend using it. Even the callback syntax that you’re using for Functions is legacy and you should move away from that.

With that being said, I think you can try to use Netlify CLI to bundle the Functions and deploy them to Netlify. I don’t know how exactly this would work with Gatsby Cloud, but worth a try.