Am I able to organise my functions into folders?

(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.

- lamda
  - some-auth-file.js
- src 
  - lamda
    - auth
      - some-auth-file.ts

Is it possible to use folders to organise?

hey there, did you see this thread already? it might answer some of your questions.

Hi @perry
The threads solution is to add
command = "echo 'this is only here so that netlify deploys functions within folders'"

I already have a command in my netlify.toml

[build]
  command = "yarn build"
  functions = "lambda"
  publish = "build"

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.

Hope that helps.

Using a folder of the same name will just create the same issue though. I want to be able to group like functions in a folder.

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.

Hope that helps.

Thanks for this.
But the thing I’m still wondering is, can you have more than one file in this folder? function-deploy-test/functions/zisi-function at master · netlify/function-deploy-test · GitHub
It’s OK if you can’t, just would be easier to organise things.

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.