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
+67-29Lines changed: 67 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -122,33 +122,49 @@ The normal Serverless deploy procedure will automatically bundle with Webpack:
122
122
- Install Serverless Webpack as above
123
123
- Deploy with `serverless deploy`
124
124
125
-
### Simulate API Gateway locally
125
+
### Usage with serverless-offline
126
126
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.
130
129
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
+
...
133
139
```
134
140
135
-
Options are:
141
+
Run `serverless offline` or `serverless offline start` to start the Lambda/API simulation.
136
142
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).
138
144
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
141
146
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:
142
154
```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
150
159
```
151
160
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
+
152
168
### Run a function locally
153
169
154
170
To run your bundled functions locally you can:
@@ -175,18 +191,6 @@ Options are:
175
191
- `--function`or `-f` (required) is the name of the function to run
176
192
- `--path`or `-p` (optional) is a JSON file path used as the function input event
177
193
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
-
190
194
### Bundle with webpack
191
195
192
196
To just bundle and see the output result use:
@@ -199,6 +203,38 @@ Options are:
199
203
200
204
- `--out`or `-o` (optional) The output directory. Defaults to `.webpack`.
201
205
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
+
202
238
## Example with Babel
203
239
204
240
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:
0 commit comments