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
This plugin is updated by its users, I just do maintenance and ensure that PRs are relevant to the community. In other words, if you [find a bug or want a new feature](https://github.com/dherault/serverless-offline/issues), please help us by becoming one of the [contributors](https://github.com/dherault/serverless-offline/graphs/contributors):v: ! See the [contributing section](#contributing).
27
29
28
30
## Documentation
29
31
30
-
-[Installation](#installation)
31
-
-[Usage and command line options](#usage-and-command-line-options)
32
-
-[Usage with Babel](#usage-with-babel)
33
-
-[Token authorizers](#token-authorizers)
34
-
-[Custom authorizers](#custom-authorizers)
35
-
-[AWS API Gateway features](#aws-api-gateway-features)
36
-
-[Velocity nuances](#velocity-nuances)
37
-
-[Debug process](#debug-process)
38
-
-[Scoped execution](#scoped-execution)
39
-
-[Simulation quality](#simulation-quality)
40
-
-[Credits and inspiration](#credits-and-inspiration)
41
-
-[Contributing](#contributing)
42
-
-[License](#license)
32
+
*[Installation](#installation)
33
+
*[Usage and command line options](#usage-and-command-line-options)
34
+
*[Usage with Babel](#usage-with-babel)
35
+
*[Token authorizers](#token-authorizers)
36
+
*[Custom authorizers](#custom-authorizers)
37
+
*[AWS API Gateway features](#aws-api-gateway-features)
38
+
*[Velocity nuances](#velocity-nuances)
39
+
*[Debug process](#debug-process)
40
+
*[Scoped execution](#scoped-execution)
41
+
*[Simulation quality](#simulation-quality)
42
+
*[Credits and inspiration](#credits-and-inspiration)
43
+
*[Contributing](#contributing)
44
+
*[License](#license)
43
45
44
46
## Installation
45
47
@@ -52,6 +54,7 @@ First, add Serverless Offline to your project:
52
54
Then inside your project's `serverless.yml` file add following entry to the plugins section: `serverless-offline`. If there is no plugin section you will need to add it to the file.
53
55
54
56
It should look something like this:
57
+
55
58
```YAML
56
59
plugins:
57
60
- serverless-offline
@@ -61,7 +64,7 @@ You can check wether you have successfully installed the plugin by running the s
61
64
62
65
`serverless`
63
66
64
-
the console should display *Offline* as one of the plugins now available in your Serverless project.
67
+
the console should display _Offline_ as one of the plugins now available in your Serverless project.
65
68
66
69
## Usage and command line options
67
70
@@ -108,11 +111,11 @@ Options passed on the command line override YAML options.
108
111
109
112
By default you can send your requests to `http://localhost:3000/`. Please note that:
110
113
111
-
-You'll need to restart the plugin if you modify your `serverless.yml` or any of the default velocity template files.
112
-
-The event object passed to your λs has one extra key: `{ isOffline: true }`. Also, `process.env.IS_OFFLINE` is `true`.
113
-
-When no Content-Type header is set on a request, API Gateway defaults to `application/json`, and so does the plugin.
114
-
But if you send an `application/x-www-form-urlencoded` or a `multipart/form-data` body with an `application/json` (or no) Content-Type, API Gateway won't parse your data (you'll get the ugly raw as input), whereas the plugin will answer 400 (malformed JSON).
115
-
Please consider explicitly setting your requests' Content-Type and using separate templates.
114
+
* You'll need to restart the plugin if you modify your `serverless.yml` or any of the default velocity template files.
115
+
* The event object passed to your λs has one extra key: `{ isOffline: true }`. Also, `process.env.IS_OFFLINE` is `true`.
116
+
* When no Content-Type header is set on a request, API Gateway defaults to `application/json`, and so does the plugin.
117
+
But if you send an `application/x-www-form-urlencoded` or a `multipart/form-data` body with an `application/json` (or no) Content-Type, API Gateway won't parse your data (you'll get the ugly raw as input), whereas the plugin will answer 400 (malformed JSON).
118
+
Please consider explicitly setting your requests' Content-Type and using separate templates.
116
119
117
120
## Usage with Babel
118
121
@@ -123,6 +126,7 @@ To do so you need to install (at least) the es2015 preset in your project folder
123
126
124
127
Your λ handlers can be required with `babel-register`.
125
128
To do so, in your `serverless.yml` file, set options to be passed to babel-register like this:
@@ -178,16 +183,19 @@ Serverless-offline will emulate the behaviour of APIG and create a random token
178
183
Only [custom authorizers](https://aws.amazon.com/blogs/compute/introducing-custom-authorizers-in-amazon-api-gateway/) are supported. Custom authorizers are executed before a Lambda function is executed and return an Error or a Policy document.
179
184
180
185
The Custom authorizer is passed an `event` object as below:
@@ -276,6 +288,7 @@ You can set your response's headers using ResponseParameters.
276
288
May not work properly. Please PR. (Difficulty: hard?)
277
289
278
290
Example response velocity template:
291
+
279
292
```javascript
280
293
"responseParameters": {
281
294
"method.response.header.X-Powered-By":"Serverless", // a string
@@ -287,6 +300,7 @@ Example response velocity template:
287
300
## Velocity nuances
288
301
289
302
Consider this requestTemplate for a POST endpoint:
303
+
290
304
```json
291
305
"application/json": {
292
306
"payload": "$input.json('$')",
@@ -298,6 +312,7 @@ Consider this requestTemplate for a POST endpoint:
298
312
Now let's make a request with this body: `{ "id": 1 }`
299
313
300
314
AWS parses the event as such:
315
+
301
316
```javascript
302
317
{
303
318
"payload": {
@@ -309,6 +324,7 @@ AWS parses the event as such:
309
324
```
310
325
311
326
Whereas Offline parses:
327
+
312
328
```javascript
313
329
{
314
330
"payload": {
@@ -327,9 +343,9 @@ You may find other differences.
327
343
328
344
Serverless offline plugin will respond to the overall framework settings and output additional information to the console in debug mode. In order to do this you will have to set the `SLS_DEBUG` environmental variable. You can run the following in the command line to switch to debug mode execution.
329
345
330
-
>Unix:`export SLS_DEBUG=*`
346
+
>Unix: `export SLS_DEBUG=*`
331
347
332
-
>Windows: `SET SLS_DEBUG=*`
348
+
>Windows: `SET SLS_DEBUG=*`
333
349
334
350
Interactive debugging is also possible for your project if you have installed the node-inspector module and chrome browser. You can then run the following command line inside your project's root.
335
351
@@ -343,6 +359,16 @@ The system will start in wait status. This will also automatically start the chr
343
359
344
360
Depending on the breakpoint, you may need to call the URL path for your function in seperate browser window for your serverless function to be run and made available for debugging.
345
361
362
+
## Resource permissions and AWS profile
363
+
364
+
Lambda functions assume an IAM role during execution: the framework creates this role and set all the permission provided in the `iamRoleStatements` section of `serverless.yml`.
365
+
366
+
However, serverless offline makes use of your local AWS profile credentials to run the lambda functions and that might result in a different set of permissions. By default, the aws-sdk would load credentials for you default AWS profile specified in your configuration file.
367
+
368
+
You can change this profile directly in the code or by setting proper environment variables. Setting the `AWS_PROFILE` environment variable before calling `serverless` offline to a different profile would effectively change the credentials, e.g.
369
+
370
+
`AWS_PROFILE=<profile> serverless offline`
371
+
346
372
## Scoped execution
347
373
348
374
Serverless offline plugin can invoke shell scripts when a simulated server has been started up for the purposes of integration testing. Downstream plugins may tie into the
@@ -353,26 +379,25 @@ Serverless offline plugin can invoke shell scripts when a simulated server has b
353
379
## Simulation quality
354
380
355
381
This plugin simulates API Gateway for many practical purposes, good enough for development - but is not a perfect simulator.
356
-
Specifically, Lambda currently runs on Node v4.3.2 and v6.10.0, whereas *Offline* runs on your own runtime where no memory limits are enforced.
382
+
Specifically, Lambda currently runs on Node v4.3.2 and v6.10.0, whereas _Offline_ runs on your own runtime where no memory limits are enforced.
357
383
358
384
## Usage with serverless-offline and serverless-webpack plugin
359
385
360
-
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 ressources.
386
+
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 ressources.
361
387
362
-
Add plugins to your `serverless.yml` file:
363
-
```yaml
364
-
plugins:
365
-
- serverless-webpack
366
-
- serverless-dynamodb-local
367
-
- serverless-offline #serverless-offline needs to be last in the list
368
-
```
388
+
Add plugins to your `serverless.yml` file:
369
389
390
+
```yaml
391
+
plugins:
392
+
- serverless-webpack
393
+
- serverless-dynamodb-local
394
+
- serverless-offline #serverless-offline needs to be last in the list
395
+
```
370
396
371
397
## Credits and inspiration
372
398
373
399
This plugin was initially a fork of [Nopik](https://github.com/Nopik/)'s [Serverless-serve](https://github.com/Nopik/serverless-serve).
0 commit comments