serverless-offline 8.5.0 → 8.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -77
- package/dist/ServerlessOffline.js +27 -8
- package/dist/config/supportedRuntimes.js +1 -1
- package/dist/debugLog.js +3 -1
- package/dist/events/{http/authCanExecuteResource.js → authCanExecuteResource.js} +0 -0
- package/dist/events/{http/authFunctionNameExtractor.js → authFunctionNameExtractor.js} +1 -1
- package/dist/events/{http/authMatchPolicyResource.js → authMatchPolicyResource.js} +0 -0
- package/dist/events/authValidateContext.js +53 -0
- package/dist/events/http/Endpoint.js +3 -1
- package/dist/events/http/HttpServer.js +28 -21
- package/dist/events/http/OfflineEndpoint.js +23 -25
- package/dist/events/http/createAuthScheme.js +23 -12
- package/dist/events/http/createJWTAuthScheme.js +6 -2
- package/dist/events/http/lambda-events/LambdaIntegrationEvent.js +26 -0
- package/dist/events/http/lambda-events/LambdaProxyIntegrationEvent.js +16 -14
- package/dist/events/http/lambda-events/LambdaProxyIntegrationEventV2.js +22 -12
- package/dist/events/http/lambda-events/VelocityContext.js +3 -1
- package/dist/events/http/lambda-events/renderVelocityTemplateObject.js +4 -1
- package/dist/events/schedule/Schedule.js +10 -9
- package/dist/events/websocket/HttpServer.js +3 -1
- package/dist/events/websocket/WebSocketClients.js +224 -5
- package/dist/events/websocket/WebSocketServer.js +5 -6
- package/dist/events/websocket/lambda-events/WebSocketAuthorizerEvent.js +99 -0
- package/dist/events/websocket/lambda-events/index.js +8 -0
- package/dist/index.js +0 -4
- package/dist/lambda/HttpServer.js +3 -1
- package/dist/lambda/Lambda.js +5 -1
- package/dist/lambda/LambdaFunction.js +1 -1
- package/dist/lambda/handler-runner/HandlerRunner.js +0 -27
- package/dist/lambda/handler-runner/child-process-runner/childProcessHelper.js +15 -6
- package/dist/lambda/handler-runner/docker-runner/DockerContainer.js +6 -5
- package/dist/lambda/handler-runner/go-runner/GoRunner.js +34 -15
- package/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js +23 -14
- package/dist/lambda/handler-runner/java-runner/JavaRunner.js +4 -3
- package/dist/lambda/handler-runner/python-runner/PythonRunner.js +15 -10
- package/dist/lambda/handler-runner/ruby-runner/RubyRunner.js +3 -6
- package/dist/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js +3 -1
- package/dist/utils/generateHapiPath.js +1 -1
- package/dist/utils/getHttpApiCorsConfig.js +4 -8
- package/dist/utils/index.js +11 -4
- package/dist/utils/lowerCaseKeys.js +14 -0
- package/dist/utils/resolveJoins.js +4 -2
- package/package.json +26 -29
- package/dist/checkEngine.js +0 -21
package/README.md
CHANGED
|
@@ -45,15 +45,17 @@ This plugin is updated by its users, I just do maintenance and ensure that PRs a
|
|
|
45
45
|
- [Usage with `invoke`](#usage-with-invoke)
|
|
46
46
|
- [The `process.env.IS_OFFLINE` variable](#the-processenvis_offline-variable)
|
|
47
47
|
- [Docker and Layers](#docker-and-layers)
|
|
48
|
-
- [
|
|
49
|
-
- [
|
|
50
|
-
- [
|
|
51
|
-
- [
|
|
52
|
-
- [
|
|
48
|
+
- [Authorizers](#authorizers)
|
|
49
|
+
- [Token authorizers](#token-authorizers)
|
|
50
|
+
- [Custom authorizers](#custom-authorizers)
|
|
51
|
+
- [Remote authorizers](#remote-authorizers)
|
|
52
|
+
- [JWT authorizers](#jwt-authorizers)
|
|
53
|
+
- [Serverless plugin authorizers](#serverless-plugin-authorizers)
|
|
53
54
|
- [Custom headers](#custom-headers)
|
|
54
55
|
- [Environment variables](#environment-variables)
|
|
55
56
|
- [AWS API Gateway Features](#aws-api-gateway-features)
|
|
56
57
|
- [Velocity Templates](#velocity-templates)
|
|
58
|
+
- [Velocity nuances](#velocity-nuances)
|
|
57
59
|
- [CORS](#cors)
|
|
58
60
|
- [Catch-all Path Variables](#catch-all-path-variables)
|
|
59
61
|
- [ANY method](#any-method)
|
|
@@ -61,13 +63,10 @@ This plugin is updated by its users, I just do maintenance and ensure that PRs a
|
|
|
61
63
|
- [HTTP Proxy](#http-proxy)
|
|
62
64
|
- [Response parameters](#response-parameters)
|
|
63
65
|
- [WebSocket](#websocket)
|
|
64
|
-
- [Usage with Webpack](#usage-with-webpack)
|
|
65
|
-
- [Velocity nuances](#velocity-nuances)
|
|
66
66
|
- [Debug process](#debug-process)
|
|
67
67
|
- [Resource permissions and AWS profile](#resource-permissions-and-aws-profile)
|
|
68
|
-
- [Scoped execution](#scoped-execution)
|
|
69
68
|
- [Simulation quality](#simulation-quality)
|
|
70
|
-
- [Usage with
|
|
69
|
+
- [Usage with other plugins](#usage-with-other-plugins)
|
|
71
70
|
- [Credits and inspiration](#credits-and-inspiration)
|
|
72
71
|
- [License](#license)
|
|
73
72
|
- [Contributing](#contributing)
|
|
@@ -138,7 +137,7 @@ All CLI options are optional:
|
|
|
138
137
|
--resourceRoutes Turns on loading of your HTTP proxy settings from serverless.yml
|
|
139
138
|
--useChildProcesses Run handlers in a child process
|
|
140
139
|
--useDocker Run handlers in a docker container.
|
|
141
|
-
--useWorkerThreads Uses worker threads
|
|
140
|
+
--useWorkerThreads Uses worker threads to run handlers.
|
|
142
141
|
--webSocketHardTimeout Set WebSocket hard timeout in seconds to reproduce AWS limits (https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html#apigateway-execution-service-websocket-limits-table). Default: 7200 (2 hours)
|
|
143
142
|
--webSocketIdleTimeout Set WebSocket idle timeout in seconds to reproduce AWS limits (https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html#apigateway-execution-service-websocket-limits-table). Default: 600 (10 minutes)
|
|
144
143
|
--websocketPort WebSocket port to listen on. Default: 3001
|
|
@@ -244,7 +243,7 @@ to calling it via `aws-sdk`.
|
|
|
244
243
|
|
|
245
244
|
## The `process.env.IS_OFFLINE` variable
|
|
246
245
|
|
|
247
|
-
Will be `"true"` in your handlers and
|
|
246
|
+
Will be `"true"` in your handlers and throughout the plugin.
|
|
248
247
|
|
|
249
248
|
## Docker and Layers
|
|
250
249
|
|
|
@@ -312,13 +311,15 @@ For certain programming languages and frameworks, it's desirable to be able to w
|
|
|
312
311
|
|
|
313
312
|
By default layers are downloaded on a per-project basis, however, if you want to share them across projects, you can download them to a common place. For example, `layersDir: /tmp/layers` would allow them to be shared across projects. Make sure when using this setting that the directory you are writing layers to can be shared by docker.
|
|
314
313
|
|
|
315
|
-
##
|
|
314
|
+
## Authorizers
|
|
315
|
+
|
|
316
|
+
### Token authorizers
|
|
316
317
|
|
|
317
318
|
As defined in the [Serverless Documentation](https://serverless.com/framework/docs/providers/aws/events/apigateway/#setting-api-keys-for-your-rest-api) you can use API Keys as a simple authentication method.
|
|
318
319
|
|
|
319
320
|
Serverless-offline will emulate the behaviour of APIG and create a random token that's printed on the screen. With this token you can access your private methods adding `x-api-key: generatedToken` to your request header. All api keys will share the same token. To specify a custom token use the `--apiKey` cli option.
|
|
320
321
|
|
|
321
|
-
|
|
322
|
+
### Custom authorizers
|
|
322
323
|
|
|
323
324
|
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.
|
|
324
325
|
|
|
@@ -344,7 +345,7 @@ The plugin only supports retrieving Tokens from headers. You can configure the h
|
|
|
344
345
|
}
|
|
345
346
|
```
|
|
346
347
|
|
|
347
|
-
|
|
348
|
+
### Remote authorizers
|
|
348
349
|
|
|
349
350
|
You are able to mock the response from remote authorizers by setting the environmental variable `AUTHORIZER` before running `sls offline start`
|
|
350
351
|
|
|
@@ -354,14 +355,14 @@ Example:
|
|
|
354
355
|
|
|
355
356
|
> Windows: `SET AUTHORIZER='{"principalId": "123"}'`
|
|
356
357
|
|
|
357
|
-
|
|
358
|
+
### JWT authorizers
|
|
358
359
|
|
|
359
360
|
For HTTP APIs, [JWT authorizers](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-jwt-authorizer.html)
|
|
360
361
|
defined in the `serverless.yml` can be used to validate the token and scopes in the token. However at this time,
|
|
361
362
|
the signature of the JWT is not validated with the defined issuer. Since this is a security risk, this feature is
|
|
362
363
|
only enabled with the `--ignoreJWTSignature` flag. Make sure to only set this flag for local development work.
|
|
363
364
|
|
|
364
|
-
|
|
365
|
+
### Serverless plugin authorizers
|
|
365
366
|
|
|
366
367
|
If your authentication needs are custom and not satisfied by the existing capabilities of the Serverless offline project, you can inject your own authentication strategy. To inject a custom strategy for Lambda invocation, you define a custom variable under `serverless-offline` called `authenticationProvider` in the serverless.yml file. The value of the custom variable will be used to `require(your authenticationProvider value)` where the location is expected to return a function with the following signature.
|
|
367
368
|
|
|
@@ -423,6 +424,47 @@ For example,
|
|
|
423
424
|
if your function is in code-file: `helloworld.js`,
|
|
424
425
|
your response template should be in file: `helloworld.res.vm` and your request template in file `helloworld.req.vm`.
|
|
425
426
|
|
|
427
|
+
#### Velocity nuances
|
|
428
|
+
|
|
429
|
+
Consider this requestTemplate for a POST endpoint:
|
|
430
|
+
|
|
431
|
+
```json
|
|
432
|
+
"application/json": {
|
|
433
|
+
"payload": "$input.json('$')",
|
|
434
|
+
"id_json": "$input.json('$.id')",
|
|
435
|
+
"id_path": "$input.path('$').id"
|
|
436
|
+
}
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
Now let's make a request with this body: `{ "id": 1 }`
|
|
440
|
+
|
|
441
|
+
AWS parses the event as such:
|
|
442
|
+
|
|
443
|
+
```javascript
|
|
444
|
+
{
|
|
445
|
+
"payload": {
|
|
446
|
+
"id": 1
|
|
447
|
+
},
|
|
448
|
+
"id_json": 1,
|
|
449
|
+
"id_path": "1" // Notice the string
|
|
450
|
+
}
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
Whereas Offline parses:
|
|
454
|
+
|
|
455
|
+
```javascript
|
|
456
|
+
{
|
|
457
|
+
"payload": {
|
|
458
|
+
"id": 1
|
|
459
|
+
},
|
|
460
|
+
"id_json": 1,
|
|
461
|
+
"id_path": 1 // Notice the number
|
|
462
|
+
}
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
Accessing an attribute after using `$input.path` will return a string on AWS (expect strings like `"1"` or `"true"`) but not with Offline (`1` or `true`).
|
|
466
|
+
You may find other differences.
|
|
467
|
+
|
|
426
468
|
### CORS
|
|
427
469
|
|
|
428
470
|
[Serverless doc](https://serverless.com/framework/docs/providers/aws/events/apigateway#enabling-cors)
|
|
@@ -531,72 +573,66 @@ Where the `event` is received in the lambda handler function.
|
|
|
531
573
|
|
|
532
574
|
There's support for [websocketsApiRouteSelectionExpression](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-selection-expressions.html) in it's basic form: `$request.body.x.y.z`, where the default value is `$request.body.action`.
|
|
533
575
|
|
|
534
|
-
|
|
576
|
+
## Debug process
|
|
535
577
|
|
|
536
|
-
|
|
578
|
+
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.
|
|
537
579
|
|
|
538
|
-
|
|
580
|
+
> Unix: `export SLS_DEBUG=*`
|
|
539
581
|
|
|
540
|
-
|
|
582
|
+
> Windows: `SET SLS_DEBUG=*`
|
|
541
583
|
|
|
542
|
-
|
|
584
|
+
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.
|
|
543
585
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
"payload": "$input.json('$')",
|
|
547
|
-
"id_json": "$input.json('$.id')",
|
|
548
|
-
"id_path": "$input.path('$').id"
|
|
549
|
-
}
|
|
550
|
-
```
|
|
586
|
+
Initial installation:
|
|
587
|
+
`npm install -g node-inspector`
|
|
551
588
|
|
|
552
|
-
|
|
589
|
+
For each debug run:
|
|
590
|
+
`node-debug sls offline`
|
|
553
591
|
|
|
554
|
-
|
|
592
|
+
The system will start in wait status. This will also automatically start the chrome browser and wait for you to set breakpoints for inspection. Set the breakpoints as needed and, then, click the play button for the debugging to continue.
|
|
555
593
|
|
|
556
|
-
|
|
557
|
-
{
|
|
558
|
-
"payload": {
|
|
559
|
-
"id": 1
|
|
560
|
-
},
|
|
561
|
-
"id_json": 1,
|
|
562
|
-
"id_path": "1" // Notice the string
|
|
563
|
-
}
|
|
564
|
-
```
|
|
594
|
+
Depending on the breakpoint, you may need to call the URL path for your function in separate browser window for your serverless function to be run and made available for debugging.
|
|
565
595
|
|
|
566
|
-
|
|
596
|
+
### Interactive Debugging with Visual Studio Code (VSC)
|
|
567
597
|
|
|
568
|
-
|
|
598
|
+
With newer versions of node (6.3+) the node inspector is already part of your node environment and you can take advantage of debugging inside your IDE with source-map support. Here is the example configuration to debug interactively with VSC. It has two steps.
|
|
599
|
+
|
|
600
|
+
#### Step 1 : Adding a launch configuration in IDE
|
|
601
|
+
|
|
602
|
+
Add a new [launch configuration](https://code.visualstudio.com/docs/editor/debugging) to VSC like this:
|
|
603
|
+
|
|
604
|
+
```json
|
|
569
605
|
{
|
|
570
|
-
"
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
"
|
|
574
|
-
"
|
|
606
|
+
"type": "node",
|
|
607
|
+
"request": "launch",
|
|
608
|
+
"name": "Debug Serverless Offline",
|
|
609
|
+
"cwd": "${workspaceFolder}",
|
|
610
|
+
"runtimeExecutable": "npm",
|
|
611
|
+
"runtimeArgs": ["run", "debug"],
|
|
612
|
+
"sourceMaps": true
|
|
575
613
|
}
|
|
576
614
|
```
|
|
577
615
|
|
|
578
|
-
|
|
579
|
-
You may find other differences.
|
|
616
|
+
#### Step2 : Adding a debug script
|
|
580
617
|
|
|
581
|
-
|
|
618
|
+
You will also need to add a `debug` script reference in your `package.json file`
|
|
582
619
|
|
|
583
|
-
|
|
620
|
+
Add this to the `scripts` section:
|
|
584
621
|
|
|
585
|
-
> Unix: `export SLS_DEBUG
|
|
586
|
-
|
|
587
|
-
> Windows: `SET SLS_DEBUG=*`
|
|
622
|
+
> Unix/Mac: `"debug" : "export SLS_DEBUG=* && node --inspect /usr/local/bin/serverless offline"`
|
|
588
623
|
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
Initial installation:
|
|
592
|
-
`npm install -g node-inspector`
|
|
624
|
+
> Windows: `"debug": "SET SLS_DEBUG=* && node --inspect node_modules\\serverless\\bin\\serverless offline"`
|
|
593
625
|
|
|
594
|
-
|
|
595
|
-
`node-debug sls offline`
|
|
626
|
+
Example:
|
|
596
627
|
|
|
597
|
-
|
|
628
|
+
```json
|
|
629
|
+
....
|
|
630
|
+
"scripts": {
|
|
631
|
+
"debug" : "SET SLS_DEBUG=* && node --inspect node_modules\\serverless\\bin\\serverless offline"
|
|
632
|
+
}
|
|
633
|
+
```
|
|
598
634
|
|
|
599
|
-
|
|
635
|
+
In VSC, you can, then, add breakpoints to your code. To start a debug sessions you can either start your script in `package.json` by clicking the hovering debug intellisense icon or by going to your debug pane and selecting the Debug Serverless Offline configuration.
|
|
600
636
|
|
|
601
637
|
## Resource permissions and AWS profile
|
|
602
638
|
|
|
@@ -608,28 +644,33 @@ You can change this profile directly in the code or by setting proper environmen
|
|
|
608
644
|
|
|
609
645
|
`AWS_PROFILE=<profile> serverless offline`
|
|
610
646
|
|
|
611
|
-
## Scoped execution
|
|
612
|
-
|
|
613
|
-
Downstream plugins may tie into the `before:offline:start:end` hook to release resources when the server is shutting down.
|
|
614
|
-
|
|
615
647
|
## Simulation quality
|
|
616
648
|
|
|
617
649
|
This plugin simulates API Gateway for many practical purposes, good enough for development - but is not a perfect simulator.
|
|
618
650
|
Specifically, Lambda currently runs on Node.js v10.x, v12.x and v14.x ([AWS Docs](https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html)), whereas _Offline_ runs on your own runtime where no memory limits are enforced.
|
|
619
651
|
|
|
620
|
-
## Usage with
|
|
652
|
+
## Usage with other plugins
|
|
621
653
|
|
|
622
|
-
|
|
654
|
+
When combining this plugin with other plugins there are a few things that you need to keep in mind.
|
|
623
655
|
|
|
624
|
-
|
|
656
|
+
You should run `serverless offline start` instead of `serverless offline`. The `start` command fires the `offline:start:init` and `offline:start:end` lifecycle hooks which can be used by other plugins to process your code, add resources, perform cleanups, etc.
|
|
657
|
+
|
|
658
|
+
The order in which plugins are added to `serverless.yml` is relevant.
|
|
659
|
+
Plugins are executed in order, so plugins that process your code or add resources should be added first so they are ready when this plugin starts.
|
|
660
|
+
|
|
661
|
+
For example:
|
|
625
662
|
|
|
626
663
|
```yaml
|
|
627
664
|
plugins:
|
|
628
|
-
- serverless-
|
|
629
|
-
- serverless-
|
|
630
|
-
- serverless-
|
|
665
|
+
- serverless-middleware # modifies some of your handler based on configuration
|
|
666
|
+
- serverless-webpack # package your javascript handlers using webpack
|
|
667
|
+
- serverless-dynamodb-local # adds a local dynamo db
|
|
668
|
+
- serverless-offline # runs last so your code has been pre-processed and dynamo is ready
|
|
631
669
|
```
|
|
632
670
|
|
|
671
|
+
That works because all those plugins listen to the `offline:start:init` to do their processing.
|
|
672
|
+
Similarly they listen to `offline:start:end` to perform cleanup (stop dynamo db, remove temporary files, etc).
|
|
673
|
+
|
|
633
674
|
## Credits and inspiration
|
|
634
675
|
|
|
635
676
|
This plugin was initially a fork of [Nopik](https://github.com/Nopik/)'s [Serverless-serve](https://github.com/Nopik/serverless-serve).
|
|
@@ -767,10 +808,10 @@ We try to follow [Airbnb's JavaScript Style Guide](https://github.com/airbnb/jav
|
|
|
767
808
|
| :------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------: |
|
|
768
809
|
| [lteacher](https://github.com/lteacher) | [martinmicunda](https://github.com/martinmicunda) | [nori3tsu](https://github.com/nori3tsu) | [ppasmanik](https://github.com/ppasmanik) | [ryanzyy](https://github.com/ryanzyy) |
|
|
769
810
|
|
|
770
|
-
| [<img alt="m0ppers" src="https://avatars3.githubusercontent.com/u/819421?v=4&s=117" width="117">](https://github.com/m0ppers) | [<img alt="footballencarta" src="https://avatars0.githubusercontent.com/u/1312258?v=4&s=117" width="117">](https://github.com/footballencarta) | [<img alt="bryanvaz" src="https://avatars0.githubusercontent.com/u/9157498?v=4&s=117" width="117">](https://github.com/bryanvaz) | [<img alt="njyjn" src="https://avatars.githubusercontent.com/u/10694375?v=4&s=117" width="117">](https://github.com/njyjn) |
|
|
771
|
-
| :---------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------: |
|
|
772
|
-
| [m0ppers](https://github.com/m0ppers) | [footballencarta](https://github.com/footballencarta) | [bryanvaz](https://github.com/bryanvaz) | [njyjn](https://github.com/njyjn) | [kdybicz](https://github.com/kdybicz)
|
|
811
|
+
| [<img alt="m0ppers" src="https://avatars3.githubusercontent.com/u/819421?v=4&s=117" width="117">](https://github.com/m0ppers) | [<img alt="footballencarta" src="https://avatars0.githubusercontent.com/u/1312258?v=4&s=117" width="117">](https://github.com/footballencarta) | [<img alt="bryanvaz" src="https://avatars0.githubusercontent.com/u/9157498?v=4&s=117" width="117">](https://github.com/bryanvaz) | [<img alt="njyjn" src="https://avatars.githubusercontent.com/u/10694375?v=4&s=117" width="117">](https://github.com/njyjn) | [<img alt="kdybicz" src="https://avatars.githubusercontent.com/u/13134892?v=4" width="117">](https://github.com/kdybicz) |
|
|
812
|
+
| :---------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------: | ------------------------------------------------------------------------------------------------------------------------ |
|
|
813
|
+
| [m0ppers](https://github.com/m0ppers) | [footballencarta](https://github.com/footballencarta) | [bryanvaz](https://github.com/bryanvaz) | [njyjn](https://github.com/njyjn) | [kdybicz](https://github.com/kdybicz) |
|
|
773
814
|
|
|
774
|
-
| [<img alt="ericctsf" src="https://avatars.githubusercontent.com/u/42775388?
|
|
775
|
-
|
|
|
776
|
-
|
|
|
815
|
+
| [<img alt="ericctsf" src="https://avatars.githubusercontent.com/u/42775388?v=4" width="117">](https://github.com/ericctsf) | [<img alt="brazilianbytes" src="https://avatars.githubusercontent.com/u/1900570?v=4" width="117">](https://github.com/brazilianbytes) |
|
|
816
|
+
| :------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------: |
|
|
817
|
+
| [ericctsf](https://github.com/erictsf) | [brazilianbytes](https://github.com/brazilianbytes) |
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _process = _interopRequireWildcard(require("process"));
|
|
9
|
+
|
|
8
10
|
var _updateNotifier = _interopRequireDefault(require("update-notifier"));
|
|
9
11
|
|
|
10
12
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
@@ -96,6 +98,10 @@ class ServerlessOffline {
|
|
|
96
98
|
lifecycleEvents: ['init', 'ready', 'end'],
|
|
97
99
|
options: _index2.commandOptions,
|
|
98
100
|
usage: 'Simulates API Gateway to call your lambda functions offline using backward compatible initialization.'
|
|
101
|
+
},
|
|
102
|
+
functionsUpdated: {
|
|
103
|
+
type: 'entrypoint',
|
|
104
|
+
lifecycleEvents: ['cleanup']
|
|
99
105
|
}
|
|
100
106
|
},
|
|
101
107
|
lifecycleEvents: ['start'],
|
|
@@ -106,13 +112,14 @@ class ServerlessOffline {
|
|
|
106
112
|
this.hooks = {
|
|
107
113
|
'offline:start:init': this.start.bind(this),
|
|
108
114
|
'offline:start:ready': this.ready.bind(this),
|
|
115
|
+
'offline:functionsUpdated:cleanup': this.cleanupFunctions.bind(this),
|
|
109
116
|
'offline:start': this._startWithExplicitEnd.bind(this),
|
|
110
117
|
'offline:start:end': this.end.bind(this)
|
|
111
118
|
};
|
|
112
119
|
}
|
|
113
120
|
|
|
114
121
|
_printBlankLine() {
|
|
115
|
-
if (
|
|
122
|
+
if (_process.env.NODE_ENV !== 'test') {
|
|
116
123
|
if (this.log) {
|
|
117
124
|
this.log.notice();
|
|
118
125
|
} else {
|
|
@@ -124,7 +131,7 @@ class ServerlessOffline {
|
|
|
124
131
|
|
|
125
132
|
async start() {
|
|
126
133
|
// Put here so available everywhere, not just in handlers
|
|
127
|
-
|
|
134
|
+
_process.env.IS_OFFLINE = true; // check if update is available
|
|
128
135
|
|
|
129
136
|
(0, _updateNotifier.default)({
|
|
130
137
|
pkg: _package.default
|
|
@@ -162,14 +169,14 @@ class ServerlessOffline {
|
|
|
162
169
|
}
|
|
163
170
|
|
|
164
171
|
async ready() {
|
|
165
|
-
if (
|
|
172
|
+
if (_process.env.NODE_ENV !== 'test') {
|
|
166
173
|
await this._listenForTermination();
|
|
167
174
|
}
|
|
168
175
|
}
|
|
169
176
|
|
|
170
177
|
async end(skipExit) {
|
|
171
178
|
// TEMP FIXME
|
|
172
|
-
if (
|
|
179
|
+
if (_process.env.NODE_ENV === 'test' && skipExit === undefined) {
|
|
173
180
|
return;
|
|
174
181
|
}
|
|
175
182
|
|
|
@@ -200,7 +207,14 @@ class ServerlessOffline {
|
|
|
200
207
|
await Promise.all(eventModules);
|
|
201
208
|
|
|
202
209
|
if (!skipExit) {
|
|
203
|
-
|
|
210
|
+
(0, _process.exit)(0);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async cleanupFunctions() {
|
|
215
|
+
if (_classPrivateFieldLooseBase(this, _lambda)[_lambda]) {
|
|
216
|
+
(0, _serverlessLog.default)('Forcing cleanup of Lambda functions');
|
|
217
|
+
await _classPrivateFieldLooseBase(this, _lambda)[_lambda].cleanup();
|
|
204
218
|
}
|
|
205
219
|
}
|
|
206
220
|
/**
|
|
@@ -219,7 +233,7 @@ class ServerlessOffline {
|
|
|
219
233
|
|
|
220
234
|
async _listenForTermination() {
|
|
221
235
|
const command = await new Promise(resolve => {
|
|
222
|
-
|
|
236
|
+
_process.default // SIGINT will be usually sent when user presses ctrl+c
|
|
223
237
|
.on('SIGINT', () => resolve('SIGINT')) // SIGTERM is a default termination signal in many cases,
|
|
224
238
|
// for example when "killing" a subprocess spawned in node
|
|
225
239
|
// with child_process methods
|
|
@@ -381,10 +395,15 @@ class ServerlessOffline {
|
|
|
381
395
|
httpEvent.http.method = '';
|
|
382
396
|
}
|
|
383
397
|
|
|
384
|
-
|
|
385
|
-
|
|
398
|
+
if (httpEvent.http.method === '*' && httpEvent.http.path === '*') {
|
|
399
|
+
httpEvent.http.routeKey = '$default';
|
|
400
|
+
} else {
|
|
401
|
+
const resolvedMethod = httpEvent.http.method === '*' ? 'ANY' : httpEvent.http.method.toUpperCase();
|
|
402
|
+
httpEvent.http.routeKey = `${resolvedMethod} ${httpEvent.http.path}`;
|
|
403
|
+
} // Clear these properties to avoid confusion (they will be derived from the routeKey
|
|
386
404
|
// when needed later)
|
|
387
405
|
|
|
406
|
+
|
|
388
407
|
delete httpEvent.http.method;
|
|
389
408
|
delete httpEvent.http.path;
|
|
390
409
|
} else {
|
|
@@ -23,7 +23,7 @@ const supportedJava = new Set(['java8', 'java11']); // NODE.JS
|
|
|
23
23
|
exports.supportedJava = supportedJava;
|
|
24
24
|
const supportedNodejs = new Set([// deprecated, but still working
|
|
25
25
|
'nodejs4.3', 'nodejs6.10', 'nodejs8.10', // supported
|
|
26
|
-
'nodejs10.x', 'nodejs12.x', 'nodejs14.x']); // PROVIDED
|
|
26
|
+
'nodejs10.x', 'nodejs12.x', 'nodejs14.x', 'nodejs16.x']); // PROVIDED
|
|
27
27
|
|
|
28
28
|
exports.supportedNodejs = supportedNodejs;
|
|
29
29
|
const supportedProvided = new Set(['provided']); // PYTHON
|
package/dist/debugLog.js
CHANGED
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _process = require("process");
|
|
9
|
+
|
|
10
|
+
var _default = typeof _process.env.SLS_DEBUG !== 'undefined' ? console.log.bind(null, '[offline]') : () => null;
|
|
9
11
|
|
|
10
12
|
exports.default = _default;
|
|
File without changes
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = authFunctionNameExtractor;
|
|
7
7
|
|
|
8
|
-
var _serverlessLog2 = _interopRequireDefault(require("
|
|
8
|
+
var _serverlessLog2 = _interopRequireDefault(require("../serverlessLog.js"));
|
|
9
9
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
|
|
File without changes
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = authValidateContext;
|
|
7
|
+
|
|
8
|
+
var _boom = _interopRequireDefault(require("@hapi/boom"));
|
|
9
|
+
|
|
10
|
+
var _serverlessLog = _interopRequireDefault(require("../serverlessLog.js"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
keys,
|
|
16
|
+
values
|
|
17
|
+
} = Object;
|
|
18
|
+
|
|
19
|
+
function internalServerError(message) {
|
|
20
|
+
const errorType = 'AuthorizerConfigurationException';
|
|
21
|
+
|
|
22
|
+
const error = _boom.default.internal();
|
|
23
|
+
|
|
24
|
+
error.output.payload.message = message;
|
|
25
|
+
error.output.payload.error = errorType;
|
|
26
|
+
error.output.headers['x-amzn-ErrorType'] = errorType;
|
|
27
|
+
return error;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function isValidContext(context) {
|
|
31
|
+
return values(context).every(i => typeof i === 'string' || typeof i === 'boolean' || typeof i === 'number');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function transform(context) {
|
|
35
|
+
keys(context).forEach(i => {
|
|
36
|
+
context[i] = context[i].toString();
|
|
37
|
+
});
|
|
38
|
+
return context;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function authValidateContext(context, authFunName) {
|
|
42
|
+
if (typeof context !== 'object') {
|
|
43
|
+
return internalServerError('Authorizer response context must be an object');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!isValidContext(context)) {
|
|
47
|
+
const error = 'Authorizer response context values must be of type string, number, or boolean';
|
|
48
|
+
(0, _serverlessLog.default)(`Detected invalid value types returned in authorizer context: (λ: ${authFunName}). ${error}. ` + 'More info: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html');
|
|
49
|
+
return internalServerError(error);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return transform(context);
|
|
53
|
+
}
|
|
@@ -63,7 +63,9 @@ class Endpoint {
|
|
|
63
63
|
this.progress = v3Utils.progress;
|
|
64
64
|
this.writeText = v3Utils.writeText;
|
|
65
65
|
this.v3Utils = v3Utils;
|
|
66
|
-
}
|
|
66
|
+
} // TODO FIXME
|
|
67
|
+
// eslint-disable-next-line no-constructor-return
|
|
68
|
+
|
|
67
69
|
|
|
68
70
|
return this._generate();
|
|
69
71
|
} // determine whether we have function level overrides for velocity templates
|