Community: functions debugging
Netlify Functions are a huge part of what makes JAMstack sites so powerful - now you can utilize the possibilities of AWS Lambda without actually needing a AWS account. Things that you would previously need a server-side backend to accomplish, such as processing a form or triggering a series of events can now be handled without needing to run a server on your own, which can be much cheaper and easier to maintain.
That said, Functions are new territory for many, and it can feel overwhelming at first to get started. This post is a work in progress, and we’ll be continuously editing it and making it more useful for you to debug your sites and apps that use Netlify Functions.
Firstly, the official Netlify docs site on Functions should be your starting place - it contains tons of information to get you up and running the right way. We feel very sure that this massive collection of the most popular applications for Netlify Functions will also be really helpful, and you might get a lot out of this video as well.
Secondly, a huge part of Functions is testing, and we have an NPM package,
netlify-lambda, which allows you to test node functions locally.
If, for some reason, you can’t test your functions with our npm package, we recommend you try and pull out the custom code and test is separately. Because functions run on node, you can run unit tests etc like you would with any other node based code.
Thirdly, A few more bits and pieces:
- You must specify a functions directory, this can be done from the site config or in a
netlify.tomlLearn more about configuring that file.
- functions need to be bundled OR zipped with dependencies. Bundling can be done with
netlify-lambda(mentioned above). For zipping, we suggest this tool by Netlifyer David Wells.
- Functions must return a JSON string in the payload - even if it’s an error you’re returning, please make sure the content-type is
- Functions timeout after 10 seconds, and limited to 1024mb (1 gb) of memory by default. They are deployed to AWS Lambda in their us-east-1 region. Some modules, for example, Headless Chrome, require the whole 1gb of RAM!
Question not answered? Don’t fret - pop a comment below and we will be happy to help you out.