You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-10Lines changed: 33 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,24 @@
1
-
## Netlify Lambda CLI
1
+
## Netlify Lambda
2
2
3
-
This is a small CLI tool that helps with building or serving lambdas built with a simple webpack/babel setup.
3
+
This is an optional tool that helps with building or locally developing [Netlify Functions](https://www.netlify.com/docs/functions/)with a simple webpack/babel build step.
4
4
5
-
The goal is to make it easy to work with Lambda's with modern ES6 without being dependent on having the most state of the art node runtime available in the final deployment environment and with a build that can compile all modules into a single lambda file.
6
-
7
-
Since v1.0.0 the dependencies were upgraded to Webpack 4 and Babel 7.
5
+
The goal is to make it easy to write Lambda's with transpiled JS/Typescipt features and imported modules.
8
6
9
7
## Installation
10
8
11
9
**We recommend installing locally** rather than globally: `yarn add -D netlify-lambda`. This will ensure your build scripts don't assume a global install which is better for your CI/CD (for example with Netlify's buildbot).
12
10
11
+
If you don't have a [`netlify.toml`](https://www.netlify.com/docs/netlify-toml-reference/) file, you'll need one ([example](https://github.com/netlify/create-react-app-lambda/blob/master/netlify.toml)). Define the `Functions` field where the functions will be built to and served from.
12
+
13
13
## Usage
14
14
15
-
Netlify lambda installs two commands:
15
+
We expose two commands:
16
16
17
17
```
18
18
netlify-lambda serve <folder>
19
19
netlify-lambda build <folder>
20
20
```
21
21
22
-
**IMPORTANT**: Both commands depend on a `netlify.toml` file being present in your project and configuring functions for deployment.
23
-
24
22
The `serve` function will start a dev server and a file watcher for the specified folder and route requests to the relevant function at:
25
23
26
24
```
@@ -29,7 +27,13 @@ http://localhost:9000/hello -> folder/hello.js (must export a handler(event, con
29
27
30
28
The `build` function will run a single build of the functions in the folder.
31
29
32
-
There are additional options, introduced later:
30
+
**IMPORTANT**:
31
+
32
+
- You need a [`netlify.toml`](https://www.netlify.com/docs/netlify-toml-reference/) file with a `Functions` field.
33
+
- Every function needs to be a top-level js/ts/mjs file. You can have subfolders inside the `netlify-lambda` folder, but those are only for supporting files to be imported by your top level function.
34
+
- Function signatures follow the [AWS event handler](https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html) syntax but must be named `handler`. [We use Node v8](https://www.netlify.com/blog/2018/04/03/node.js-8.10-now-available-in-netlify-functions/) so `async` functions **are** supported ([beware common mistakes](https://serverless.com/blog/common-node8-mistakes-in-lambda/)!). Read [Netlify Functions docs](https://www.netlify.com/docs/functions/#javascript-lambda-functions) for more info.
35
+
36
+
There are additional CLI options, introduced below:
33
37
```bash
34
38
-h --help
35
39
-c --config
@@ -56,6 +60,7 @@ Say you are running `webpack-serve` on port 8080 and `netlify-lambda serve` on p
56
60
- If you are using with `create-react-app`, see [netlify/create-react-app-lambda](https://github.com/netlify/create-react-app-lambda/blob/f0e94f1d5a42992a2b894bfeae5b8c039a177dd9/src/setupProxy.js) for an example of how to do this with `create-react-app`. [setupProxy is partially documented in the CRA docs](https://facebook.github.io/create-react-app/docs/proxying-api-requests-in-development#configuring-the-proxy-manually).
57
61
- If you are using Gatsby, see [their Advanced Proxying docs](https://www.gatsbyjs.org/docs/api-proxy/#advanced-proxying). This is implemented in the [JAMstack Hackathon Starter](https://github.com/sw-yx/jamstack-hackathon-starter).
58
62
- If you are using Next.js, see [this issue for how to proxy](https://github.com/netlify/netlify-lambda/pull/28#issuecomment-439675503).
63
+
- If you are using Vue CLI, you may just use https://github.com/netlify/vue-cli-plugin-netlify-lambda/.
59
64
- If you are using with Angular CLI, see the instructions below.
@@ -176,6 +181,8 @@ You may also want to add `typescript @types/node @types/aws-lambda`.
176
181
177
182
3. (Optional) if you have `@types/aws-lambda` installed, your lambda functions can use the community typings for `Handler, Context, Callback`. See the typescript instructions in [create-react-app-lambda](https://github.com/netlify/create-react-app-lambda/blob/master/README.md#typescript) for an example.
178
183
184
+
Check https://github.com/sw-yx/create-react-app-lambda-typescript for a CRA + Lambda full Typescript experience.
185
+
179
186
### --static option
180
187
181
188
If you need an escape hatch and are building your lambda in some way that is incompatible with our build process, you can skip the build with the `-s` or `--static` flag. [More info here](https://github.com/netlify/netlify-lambda/pull/62).
@@ -195,13 +202,29 @@ Don't forget to search our issues in case someone has run into a similar problem
195
202
196
203
Netlify Identity is [not supported at the moment](https://github.com/netlify/netlify-lambda/issues/51) inside `netlify-lambda` function emulation, but for now you can [read the docs](https://www.netlify.com/docs/functions/#identity-and-functions) on how they should work.
197
204
205
+
## Example functions and Tutorials
206
+
207
+
You can do a great deal with lambda functions! Here are some examples for inspiration:
- Netlify's list of Function examples: https://functions-playground.netlify.com/ ([Even more in the README](https://github.com/netlify/functions))
-[Any others to suggest?](https://github.com/netlify/netlify-lambda/issues/new)
220
+
198
221
## Other community approaches
199
222
200
223
If you wish to serve the full website from lambda, [check this issue](https://github.com/netlify/netlify-lambda/issues/36).
201
224
202
225
If you wish to run this server for testing, [check this issue](https://github.com/netlify/netlify-lambda/issues/49).
203
226
204
-
If you wish to emulate more Netlify functionality locally, [check this repo](https://github.com/8eecf0d2/netlify-local).
227
+
If you wish to emulate more Netlify functionality locally, check this repo: https://github.com/8eecf0d2/netlify-local. We are considering merging the projects [here](https://github.com/netlify/netlify-lambda/issues/75).
205
228
206
229
All of the above are community maintained and not officially supported by Netlify.
0 commit comments