Building functions using netlify-lambda when deploying via netlify-cli

I have a static site that I am deploying to Netlify using netlify-cli.

It all works fine apart from the functions that I build using netlify-lambda don’t make it to the deployed site.

What configuration do I need?

Something that I tried:

After the build finished, but before uploading via the cli, I moved config and built functions to the directory that gets uploaded:

mv .netlify/functions netlify.toml _site

The site goes live, and the redirect rules I have in netlify.toml are now working, but the functions are still returning 404s.

btw the netlify.toml contains:

[build]
command = “npm install && npm run build”
functions = “.netlify/functions/”

Do I need to package them in a different way when uploading via the cli?

I just tried using the —functions flag:

netlify-cli deploy --dir=$DEPLOY_DIR --functions .netlify/functions --prod

Still getting 404s on the functions.

How do I deploy functions using the cli?

I also tried passing the unbundled folder path as the —functions flag value which seems to be what the docs are suggesting todo. Still got the 404s though.

What am I missing?

hi @mjgs, thanks for your patience - I have reached out to our functions expert Dennis, and hopefully we’ll have some more information for you on this soon.

@mjgs, firstly, I don’t recommend that you put your functions inside a hidden folder (.netlify). I suggest setting your functions folder to functions/. Also, note that you functions folder should not be included in the folder that you are deploying to your site.

That said, after you make the change in your netlify.toml file, let me know how it goes. If you still are unable to deploy your functions, please share your package.json (to check your build script) and also the site that you are deploying to.

Thanks!

I had set the functions folder according to a popular online tutorial, I will try using a non hidden folder outside the build directory.

What value do I pass to the netlify-cli —functions flag?

Is it the path to the functions folder? Or is it the compiled file outputted by netlify-lambda? or is it something else?

Hey there,
Sorry for the delay here! Would it be possible for you to share your repo? netlify-lambda can be a great tool in some cases, but I find that it can sometimes be more confusing than helpful.

If you have a package.json in your root that contains the dependencies you need for your function, and you define the functions directory (let’s say it’s functionsDir) in your netlify.toml, then running netlify deploy --functions functionsDir should work for you. We know you’ve been waiting for a while, so happy to have a look at a repo, and it’d be great to get your Netlify URL as well please!

@dennis I ended up changing my build to output to dist/functions and dist/site and these worked fine with the cli so maybe you were right about the hidden folder being an issue.

Hi @jen and thanks for the details. I had this working a few days ago, but there were some issues with the Netlify GitHub action that stopped loading for some reason. In any case it started working again the next day and it’s been working very smoothly for 2 days now.

And since you asked :slight_smile: …in case your interested these are the sites:

I post daily links to javascript, tech and dev links on my linkblog:

https://links.markjgsmith.com

The podcast is very experimental right now, mostly collected sounds and recordings, but I might start some kind of show at some stage, it will hopefully be in iTunes in the next few days.

https://podcasts.markjgsmith.com

Thanks for your help!

1 Like

thanks for sharing, @mjgs!