Skip to content

Commit 8741526

Browse files
authored
Merge pull request #144 from elastic-coders/update-serverless-offline-docs
Update docs for use with serverless-offline
2 parents f215f49 + 7c46b92 commit 8741526

File tree

1 file changed

+67
-29
lines changed

1 file changed

+67
-29
lines changed

README.md

Lines changed: 67 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -122,33 +122,49 @@ The normal Serverless deploy procedure will automatically bundle with Webpack:
122122
- Install Serverless Webpack as above
123123
- Deploy with `serverless deploy`
124124

125-
### Simulate API Gateway locally
125+
### Usage with serverless-offline
126126

127-
To start a local server that will act like the API Gateway use the following command.
128-
Your code will be reloaded upon change so that every request to your local server
129-
will serve the latest code.
127+
The plugin integrates very well with [serverless-offline][link-serverless-offline] to
128+
simulate AWS Lambda and AWS API Gateway locally.
130129

131-
```bash
132-
$ serverless webpack serve
130+
Add the plugins to your `serverless.yml` file and make sure that `serverless-webpack`
131+
precedes `serverless-offline` as the order is important:
132+
```yaml
133+
plugins:
134+
...
135+
- serverless-webpack
136+
...
137+
- serverless-offline
138+
...
133139
```
134140

135-
Options are:
141+
Run `serverless offline` or `serverless offline start` to start the Lambda/API simulation.
136142

137-
- `--port` or `-p` (optional) The local server port. Defaults to `8000`
143+
In comparison to `serverless offline`, the `start` command will fire an `init` and a `end` lifecycle hook which is needed for `serverless-offline` and e.g. `serverless-dynamodb-local` to switch off resources (see below).
138144

139-
The `serve` command will automatically look for the local `serverless.yml` and serve
140-
all the `http` events. For example this configuration will generate a GET endpoint:
145+
#### Custom paths
141146

147+
If you do not use the default path and override it in your Webpack configuration,
148+
you have use the `--location` option.
149+
150+
#### serverless-dynamodb-local
151+
152+
Configure your service the same as mentioned above, but additionally add the `serverless-dynamodb-local`
153+
plugin as follows:
142154
```yaml
143-
functions:
144-
hello:
145-
handler: handler.hello
146-
events:
147-
- http:
148-
method: get
149-
path: hello
155+
plugins:
156+
- serverless-webpack
157+
- serverless-dynamodb-local
158+
- serverless-offline
150159
```
151160

161+
Run `serverless offline start`.
162+
163+
#### Other useful options
164+
165+
You can reduce the clutter generated by `serverless-offline` with `--dontPrintOutput` and
166+
disable timeouts with `--noTimeout`.
167+
152168
### Run a function locally
153169

154170
To run your bundled functions locally you can:
@@ -175,18 +191,6 @@ Options are:
175191
- `--function` or `-f` (required) is the name of the function to run
176192
- `--path` or `-p` (optional) is a JSON file path used as the function input event
177193

178-
### Using with serverless-offline and serverless-webpack plugin
179-
180-
Run `serverless offline start`. In comparison with `serverless offline`, the `start` command will fire an `init` and a `end` lifecycle hook which is needed for serverless-offline and serverless-dynamodb-local to switch off both resources.
181-
182-
Add plugins to your `serverless.yml` file:
183-
```yaml
184-
plugins:
185-
- serverless-webpack
186-
- serverless-dynamodb-local
187-
- serverless-offline #serverless-offline needs to be last in the list
188-
```
189-
190194
### Bundle with webpack
191195

192196
To just bundle and see the output result use:
@@ -199,6 +203,38 @@ Options are:
199203

200204
- `--out` or `-o` (optional) The output directory. Defaults to `.webpack`.
201205

206+
### Simulate API Gateway locally
207+
208+
_There are plans to remove the integrated simulation functionality in favor of
209+
using serverless-offline (see [#135](https://github.com/elastic-coders/serverless-webpack/issues/135))
210+
which already does the job perfectly and fully integrates with serverless-webpack.
211+
Please consider to switch to serverless-offline if you do not use it already._
212+
213+
To start a local server that will act like the API Gateway use the following command.
214+
Your code will be reloaded upon change so that every request to your local server
215+
will serve the latest code.
216+
217+
```bash
218+
$ serverless webpack serve
219+
```
220+
221+
Options are:
222+
223+
- `--port` or `-p` (optional) The local server port. Defaults to `8000`
224+
225+
The `serve` command will automatically look for the local `serverless.yml` and serve
226+
all the `http` events. For example this configuration will generate a GET endpoint:
227+
228+
```yaml
229+
functions:
230+
hello:
231+
handler: handler.hello
232+
events:
233+
- http:
234+
method: get
235+
path: hello
236+
```
237+
202238
## Example with Babel
203239

204240
In the [`examples`][link-examples] folder there is a Serverless project using this
@@ -223,3 +259,5 @@ plugin with Babel. To try it, from inside the example folder:
223259
[link-webpack-libtarget]: https://webpack.github.io/docs/configuration.html#output-librarytarget
224260
[link-webpack-externals]: https://webpack.github.io/docs/configuration.html#externals
225261
[link-examples]: ./examples
262+
[link-serverless-offline]: https://www.npmjs.com/package/serverless-offline
263+
[link-serverless-dynamodb-local]: https://www.npmjs.com/package/serverless-dynamodb-local

0 commit comments

Comments
 (0)