(Using VSCode and Typescript)
I have many functions and would like to organise them in to folders, but when I do I get an Error during invocation - most likely because the netlify-lambda serve src/lambda call doesn’t care about my folder structure.
As mentioned here, you can use either a standalone *.js file that exports a handler (e.g. lambda/{function_name}.js ) or a folder with the same name as your *.js file in it that exports a handler (e.g. lambda/{function_name}/{function_name}.js ). The file structure is not flexible.
That said, you mentioned your folder name is lamda. Is that a typo? If not, you’ll probably need to rename that to lambda to match the netlify-lambda command.
You can organize your folders anyway you like, but during deploy, it will need to be in the file structure I mentioned. You can probably moving some files around at build time but that’ll be up to you.
I dont see how you can organize the folders anyway you like but during deploy, it will need to be in the file structure you mentioned.
Are you able to post and example or repo to help explain how I can do this, thanks so much.
So, I have a repository here: GitHub - netlify/function-deploy-test, where I have set my functions folder to functions/. I have functions in functions/ and in lambda/. I can have a functions in any folder. The only thing to note is that my build script ensures that all my functions are built into or copied into my functions/ folder during build time.
Just confirming that you can have multiple files in a function folder but only the file with the same name as the folder (functions/myfunction/myfunction.js) will run when invoking the function endpoint.