Function concepts and sharing fles between functions

A bit of feedback and a question as I look at porting an app backend rom an old and now defunct version of Zeit/Vercel.

So my overall impression is that functions provide a very nice facade to AWS Lamda functions. But, while you hide the details it’s a pretty leaky abstraction. At least as far as the docs are concerned. It would be great if you removed any assumptions about prerequisite AWS knowledge. There are several points where you mention AWS.

In the Javascript page you suddenly introduce the concept of ‘Synchronous’ functions. This seem to be as compared to Background Function given the heading structure, but it’s not clear. Especially as the example uses the ‘async’ keyword LOL.

In one place I read a mention of calling functions directly, Possibly not as a HTTP endpoint but that seems unlikely and I never saw any details. It seemed to be a ref to old functionality.

Another concept that you could explain is Bundled / Unbundled. I think I have it figured from several reads. But Unbundled get bundled by the deployment so not sure.

Hope that helps you improve the docs.

My question is about file sharing in the source without any pre deploy build steps. The options appear to be:

  • single function file per endpoint
  • a directory with several files, including the exported endpoint function
  • so called ‘unbundled’ - either of the above but with modules imported via node node_modules mechanism (hmm, what about ESM modules :))

But what about files we want to share that are our own source and not imported modules? Can we stick them in the functions folder, import them and expect them to be deployed for us? Do we put them in a specfic folder, access in another function’s folder. Or do we need to put in node module , with or without full packaging?

Or is this why yo utalk about “bundled”? you expect a pre deploy process to bundle (in the usual sense) everything into one file / folder?

I’ll explore but it would be best if this was documented as I don’t want to rely on undocumented behaviour that could change.

Cheers

Re - leaky abstraction - even the topic here is “lambda functions” :stuck_out_tongue:

Hey @slim,
Thanks for the feedback about our functions docs! We’ll discuss with our docs team.

As for your question about including source files in functions, I think you’ll be interested in following this conversation about a functions configuration property that you can currently test called… well… included_files: Discussion: enable esbuild text loader for more additional file types · Issue #392 · netlify/zip-it-and-ship-it · GitHub

Let us know what you think, either here or there!

1 Like

So my dream DX is that I can just create my JS function files, including possibly files shared between functions and possibly packages in node_modules.

Hi Jen

don’t want to mess about with building, bundling or zipping or anything like that except if “I” want to. An then I choose my tools to generate JS files in the required directories.

If AWS requires building, bundling, duplicating of files across functions or anything like that I’m happy for the netlify platform to do it transparently (in the local CLI and during CI).

At present I seem to need to understand what AWS needs and build /deploy accordingly.

Perhaps if as well as _node_modules your unbundled processing could grab files is one or more designated shared files folder structures? OR alternatively we declare which folders have publishable functions in? eg somehting like

project

  • node_modules
  • functions
    • FuncForEndPoint1
    • FuncForEndPoint2
    • SharedCodeNotExposed

code in the FuncfForEndpoint? files includes/requires files in SharedCodeNotExposed and/or node_modules

I’d be happy if SharedCodeNotExposed is pushed up to the parent folder (peer of node_modules) and I could require/include that so it gets copied and zipped for deployment to AWS as you indicate is done for unbundled functions

Does that help explain where I am coming form?

Steve

\0/ I got it working using the support for Unbundled Functions and npm support of local module paths!

Steve this repo and readme and details.

1 Like

@slim, thank you so much for coming back and sharing your solution with us! We deeply appreciate it, as it will help future Forums members who encounter something similar!