serverless-offline 8.6.0 → 8.8.1
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/CHANGELOG.md +78 -0
- package/README.md +89 -93
- package/dist/ServerlessOffline.js +14 -13
- package/dist/config/supportedRuntimes.js +1 -1
- package/dist/debugLog.js +3 -1
- package/dist/events/authValidateContext.js +53 -0
- package/dist/events/http/Endpoint.js +3 -1
- package/dist/events/http/HttpServer.js +27 -20
- package/dist/events/http/OfflineEndpoint.js +23 -25
- package/dist/events/http/createAuthScheme.js +22 -11
- 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 +17 -13
- 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 +38 -11
- package/dist/events/websocket/WebSocketServer.js +5 -6
- 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 -2
- package/dist/lambda/handler-runner/HandlerRunner.js +1 -29
- package/dist/lambda/handler-runner/child-process-runner/ChildProcessRunner.js +1 -9
- package/dist/lambda/handler-runner/child-process-runner/childProcessHelper.js +15 -6
- package/dist/lambda/handler-runner/docker-runner/DockerContainer.js +2 -4
- package/dist/lambda/handler-runner/go-runner/GoRunner.js +34 -15
- package/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js +24 -30
- package/dist/lambda/handler-runner/java-runner/JavaRunner.js +3 -1
- package/dist/lambda/handler-runner/python-runner/PythonRunner.js +15 -10
- package/dist/lambda/handler-runner/ruby-runner/RubyRunner.js +3 -4
- package/dist/lambda/handler-runner/worker-thread-runner/WorkerThreadRunner.js +0 -2
- package/dist/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js +4 -3
- 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/dist/utils/splitHandlerPathAndName.js +9 -13
- package/package.json +23 -27
- package/dist/checkEngine.js +0 -21
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
+
|
|
5
|
+
### [8.8.1](https://github.com/dherault/serverless-offline/compare/v8.8.0...v8.8.1) (2022-07-09)
|
|
6
|
+
|
|
7
|
+
### Maintenance Improvements
|
|
8
|
+
|
|
9
|
+
- remove update-notifier ([fbcd41e](https://github.com/dherault/serverless-offline/commit/fbcd41eb29fd5aa60d3ce52a734b89ed4113d893))
|
|
10
|
+
|
|
11
|
+
## [8.8.0](https://github.com/dherault/serverless-offline/compare/v8.7.0...v8.8.0) (2022-05-17)
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
- Support using go build ([#1334](https://github.com/dherault/serverless-offline/issues/1334)) ([#1356](https://github.com/dherault/serverless-offline/issues/1356)) ([a79b15c](https://github.com/dherault/serverless-offline/commit/a79b15c529b60ac0d037716cf6e475bcda8f822e))
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
- lowercase API gateway V2 event headers ([#1288](https://github.com/dherault/serverless-offline/issues/1288)) ([9ff4cf3](https://github.com/dherault/serverless-offline/commit/9ff4cf38c4f620545d95d815d0b420d134be5cb1))
|
|
20
|
+
- remove (now) useless worker thread support check ([#1406](https://github.com/dherault/serverless-offline/issues/1406)) ([1b2ae00](https://github.com/dherault/serverless-offline/commit/1b2ae0016cec385416c240b55669df038ddc5d1e))
|
|
21
|
+
- remove babel-eslint ([17adeb5](https://github.com/dherault/serverless-offline/commit/17adeb5b923d990f64e96e234297999baaca30a0))
|
|
22
|
+
- remove engine check ([#1407](https://github.com/dherault/serverless-offline/issues/1407)) ([58b2199](https://github.com/dherault/serverless-offline/commit/58b21998e2ced5eeab3ebf0a30fd1849e974befe))
|
|
23
|
+
- remove unneeded deps ([95e1fe5](https://github.com/dherault/serverless-offline/commit/95e1fe5bbc4aceb83bd8135503c3c4123006d61b))
|
|
24
|
+
- solve merge issues ([99a2578](https://github.com/dherault/serverless-offline/commit/99a25789ce6d4be718dcae470e99bde5f3ab8b86))
|
|
25
|
+
- temporary revert nested modules ([#1419](https://github.com/dherault/serverless-offline/issues/1419)) ([f4317e4](https://github.com/dherault/serverless-offline/commit/f4317e4f6bd818ed6d243b440cab9d7030b1c30d))
|
|
26
|
+
|
|
27
|
+
### Maintenance Improvements
|
|
28
|
+
|
|
29
|
+
- import from namespace ([#1405](https://github.com/dherault/serverless-offline/issues/1405)) ([ed9d6cd](https://github.com/dherault/serverless-offline/commit/ed9d6cd48fbdba26cf7a4b5aa096464fba94193e))
|
|
30
|
+
- import process explicit ([#1418](https://github.com/dherault/serverless-offline/issues/1418)) ([8893c67](https://github.com/dherault/serverless-offline/commit/8893c67718259b7d760194c74f31ee56fcd7e789))
|
|
31
|
+
- prettify docs ([2ee5b1e](https://github.com/dherault/serverless-offline/commit/2ee5b1ef56133aecbc120f2d20858411b30956d3))
|
|
32
|
+
- remove extend module, replace with Object.assign ([#1417](https://github.com/dherault/serverless-offline/issues/1417)) ([90d5169](https://github.com/dherault/serverless-offline/commit/90d516909c3c41e907d728afd47cf436f078bf97))
|
|
33
|
+
|
|
34
|
+
## [8.7.0](https://github.com/dherault/serverless-offline/compare/v8.6.0...v8.7.0) (2022-04-13)
|
|
35
|
+
|
|
36
|
+
- [Validate authorizer context response to better mimic API Gateway](https://github.com/dherault/serverless-offline/pull/1376)
|
|
37
|
+
- [Add support for the AUTHORIZER env variable for LambdaIntegration](https://github.com/dherault/serverless-offline/pull/1308)
|
|
38
|
+
|
|
39
|
+
## [8.6.0](https://github.com/dherault/serverless-offline/compare/v8.5.0...v8.6.0) (2022-04-13)
|
|
40
|
+
|
|
41
|
+
- [POC for externally triggering cleanup of lambda functions](https://github.com/dherault/serverless-offline/pull/1093)
|
|
42
|
+
- [Fixing AWS env vars](https://github.com/dherault/serverless-offline/pull/1108)
|
|
43
|
+
- [Ensure gateway IP is truthy before adding to docker args](https://github.com/dherault/serverless-offline/pull/1174)
|
|
44
|
+
- [update debugging instructions](https://github.com/dherault/serverless-offline/pull/1221)
|
|
45
|
+
- [Never remove cached node_modules or binary modules](https://github.com/dherault/serverless-offline/pull/1230)
|
|
46
|
+
- [Handle multiple cookies with the same name in the same way API Gateway does.](https://github.com/dherault/serverless-offline/pull/1249)
|
|
47
|
+
|
|
48
|
+
## [8.5.0](https://github.com/dherault/serverless-offline/compare/v8.4.0...v8.5.0) (2022-02-18)
|
|
49
|
+
|
|
50
|
+
### Features
|
|
51
|
+
|
|
52
|
+
- Add `httpEvent.operationId` to the request context ([#1325](https://github.com/dherault/serverless-offline/issues/1325)) ([e217fcb](https://github.com/dherault/serverless-offline/commit/e217fcba61fe3eae110f506268c71b350e1937da)) ([Quenby Mitchell](https://github.com/qswinson))
|
|
53
|
+
- Ensure `websocket` parity with API Gateway ([#1301](https://github.com/dherault/serverless-offline/issues/1301)) ([8f02226](https://github.com/dherault/serverless-offline/commit/8f0222644e5946c2bba8853c7ee6c224e7a33b41)) ([Christian Nuss](https://github.com/cnuss))
|
|
54
|
+
- Introduce header to override authorizer response ([#1328](https://github.com/dherault/serverless-offline/issues/1328)) ([a5158a4](https://github.com/dherault/serverless-offline/commit/a5158a489048ceee007cefa41441f841b51db59c)) ([ericctsf](https://github.com/ericctsf))
|
|
55
|
+
- Support injection of custom authentication strategy ([#1314](https://github.com/dherault/serverless-offline/issues/1314)) ([febfe77](https://github.com/dherault/serverless-offline/commit/febfe77d470b2e5e4fbfe5243b265d6a27fb84f3)) ([tom-stclair](https://github.com/tom-stclair))
|
|
56
|
+
|
|
57
|
+
### Bug Fixes
|
|
58
|
+
|
|
59
|
+
- Fix payload normalization ([#1332](https://github.com/dherault/serverless-offline/issues/1332)) ([e9e8169](https://github.com/dherault/serverless-offline/commit/e9e816996e8da9605a4a9856a60ddfbbe885e1b1)) ([Taras Romaniv](https://github.com/trsrm))
|
|
60
|
+
- Skip clearing undefined modules in `InProcessRunner` ([#1339](https://github.com/dherault/serverless-offline/issues/1339)) ([5026e43](https://github.com/dherault/serverless-offline/commit/5026e43974dd73de66bf2c82b742cc7341f7c55b)) ([Kevin Rueter](https://github.com/kerueter))
|
|
61
|
+
|
|
62
|
+
## [8.4.0](https://github.com/dherault/serverless-offline/compare/v8.3.1...v8.4.0) (2022-01-28)
|
|
63
|
+
|
|
64
|
+
### Features
|
|
65
|
+
|
|
66
|
+
- `go-runner` implementation ([#1320](https://github.com/dherault/serverless-offline/issues/1320)) ([6bb54fd](https://github.com/dherault/serverless-offline/commit/6bb54fdccebd3db61221a9b8f709414876086324))
|
|
67
|
+
- `--disableScheduledEvents` CLI param support ([#1185](https://github.com/dherault/serverless-offline/issues/1185)) ([4503567](https://github.com/dherault/serverless-offline/commit/4503567cdb8fa31ac9df98b667a403b0408f8444))
|
|
68
|
+
|
|
69
|
+
### Bug Fixes
|
|
70
|
+
|
|
71
|
+
- Handle custom authorizer 401 in non in-process runners ([#1319](https://github.com/dherault/serverless-offline/issues/1319)) ([8d61bde](https://github.com/dherault/serverless-offline/commit/8d61bde74cdfb37410a5c1952ca608e815eeb1cf))
|
|
72
|
+
- Support `httpApi` payload override on function level ([#1312](https://github.com/dherault/serverless-offline/issues/1312)) ([8db63dd](https://github.com/dherault/serverless-offline/commit/8db63dda6054198775ed3b567dc3c1dbf73eb574))
|
|
73
|
+
|
|
74
|
+
### [8.3.1](https://github.com/dherault/serverless-offline/compare/v8.3.0...v8.3.1) (2021-11-25)
|
|
75
|
+
|
|
76
|
+
### Bug Fixes
|
|
77
|
+
|
|
78
|
+
- Fix handling of modern logs (`Cannot read properties of undefined (reading 'notice')` error)
|
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
|
|
@@ -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,51 +573,6 @@ 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
|
-
## Usage with Webpack
|
|
535
|
-
|
|
536
|
-
Use [serverless-webpack](https://github.com/serverless-heaven/serverless-webpack) to compile and bundle your ES-next code
|
|
537
|
-
|
|
538
|
-
## Velocity nuances
|
|
539
|
-
|
|
540
|
-
Consider this requestTemplate for a POST endpoint:
|
|
541
|
-
|
|
542
|
-
```json
|
|
543
|
-
"application/json": {
|
|
544
|
-
"payload": "$input.json('$')",
|
|
545
|
-
"id_json": "$input.json('$.id')",
|
|
546
|
-
"id_path": "$input.path('$').id"
|
|
547
|
-
}
|
|
548
|
-
```
|
|
549
|
-
|
|
550
|
-
Now let's make a request with this body: `{ "id": 1 }`
|
|
551
|
-
|
|
552
|
-
AWS parses the event as such:
|
|
553
|
-
|
|
554
|
-
```javascript
|
|
555
|
-
{
|
|
556
|
-
"payload": {
|
|
557
|
-
"id": 1
|
|
558
|
-
},
|
|
559
|
-
"id_json": 1,
|
|
560
|
-
"id_path": "1" // Notice the string
|
|
561
|
-
}
|
|
562
|
-
```
|
|
563
|
-
|
|
564
|
-
Whereas Offline parses:
|
|
565
|
-
|
|
566
|
-
```javascript
|
|
567
|
-
{
|
|
568
|
-
"payload": {
|
|
569
|
-
"id": 1
|
|
570
|
-
},
|
|
571
|
-
"id_json": 1,
|
|
572
|
-
"id_path": 1 // Notice the number
|
|
573
|
-
}
|
|
574
|
-
```
|
|
575
|
-
|
|
576
|
-
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`).
|
|
577
|
-
You may find other differences.
|
|
578
|
-
|
|
579
576
|
## Debug process
|
|
580
577
|
|
|
581
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.
|
|
@@ -598,27 +595,22 @@ Depending on the breakpoint, you may need to call the URL path for your function
|
|
|
598
595
|
|
|
599
596
|
### Interactive Debugging with Visual Studio Code (VSC)
|
|
600
597
|
|
|
601
|
-
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.
|
|
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.
|
|
602
599
|
|
|
603
600
|
#### Step 1 : Adding a launch configuration in IDE
|
|
604
601
|
|
|
605
602
|
Add a new [launch configuration](https://code.visualstudio.com/docs/editor/debugging) to VSC like this:
|
|
606
603
|
|
|
607
604
|
```json
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
"debug"
|
|
618
|
-
],
|
|
619
|
-
"sourceMaps": true
|
|
620
|
-
}
|
|
621
|
-
|
|
605
|
+
{
|
|
606
|
+
"type": "node",
|
|
607
|
+
"request": "launch",
|
|
608
|
+
"name": "Debug Serverless Offline",
|
|
609
|
+
"cwd": "${workspaceFolder}",
|
|
610
|
+
"runtimeExecutable": "npm",
|
|
611
|
+
"runtimeArgs": ["run", "debug"],
|
|
612
|
+
"sourceMaps": true
|
|
613
|
+
}
|
|
622
614
|
```
|
|
623
615
|
|
|
624
616
|
#### Step2 : Adding a debug script
|
|
@@ -640,8 +632,7 @@ Example:
|
|
|
640
632
|
}
|
|
641
633
|
```
|
|
642
634
|
|
|
643
|
-
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
|
|
644
|
-
|
|
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.
|
|
645
636
|
|
|
646
637
|
## Resource permissions and AWS profile
|
|
647
638
|
|
|
@@ -653,28 +644,33 @@ You can change this profile directly in the code or by setting proper environmen
|
|
|
653
644
|
|
|
654
645
|
`AWS_PROFILE=<profile> serverless offline`
|
|
655
646
|
|
|
656
|
-
## Scoped execution
|
|
657
|
-
|
|
658
|
-
Downstream plugins may tie into the `before:offline:start:end` hook to release resources when the server is shutting down.
|
|
659
|
-
|
|
660
647
|
## Simulation quality
|
|
661
648
|
|
|
662
649
|
This plugin simulates API Gateway for many practical purposes, good enough for development - but is not a perfect simulator.
|
|
663
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.
|
|
664
651
|
|
|
665
|
-
## Usage with
|
|
652
|
+
## Usage with other plugins
|
|
653
|
+
|
|
654
|
+
When combining this plugin with other plugins there are a few things that you need to keep in mind.
|
|
666
655
|
|
|
667
|
-
|
|
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.
|
|
668
657
|
|
|
669
|
-
|
|
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:
|
|
670
662
|
|
|
671
663
|
```yaml
|
|
672
664
|
plugins:
|
|
673
|
-
- serverless-
|
|
674
|
-
- serverless-
|
|
675
|
-
- 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
|
|
676
669
|
```
|
|
677
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
|
+
|
|
678
674
|
## Credits and inspiration
|
|
679
675
|
|
|
680
676
|
This plugin was initially a fork of [Nopik](https://github.com/Nopik/)'s [Serverless-serve](https://github.com/Nopik/serverless-serve).
|
|
@@ -812,10 +808,10 @@ We try to follow [Airbnb's JavaScript Style Guide](https://github.com/airbnb/jav
|
|
|
812
808
|
| :------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------: |
|
|
813
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) |
|
|
814
810
|
|
|
815
|
-
| [<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) |
|
|
816
|
-
| :---------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------: |
|
|
817
|
-
| [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) |
|
|
818
814
|
|
|
819
|
-
| [<img alt="ericctsf" src="https://avatars.githubusercontent.com/u/42775388?
|
|
820
|
-
|
|
|
821
|
-
|
|
|
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,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _process = _interopRequireWildcard(require("process"));
|
|
9
9
|
|
|
10
10
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
11
11
|
|
|
@@ -117,7 +117,7 @@ class ServerlessOffline {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
_printBlankLine() {
|
|
120
|
-
if (
|
|
120
|
+
if (_process.env.NODE_ENV !== 'test') {
|
|
121
121
|
if (this.log) {
|
|
122
122
|
this.log.notice();
|
|
123
123
|
} else {
|
|
@@ -129,11 +129,7 @@ class ServerlessOffline {
|
|
|
129
129
|
|
|
130
130
|
async start() {
|
|
131
131
|
// Put here so available everywhere, not just in handlers
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
(0, _updateNotifier.default)({
|
|
135
|
-
pkg: _package.default
|
|
136
|
-
}).notify();
|
|
132
|
+
_process.env.IS_OFFLINE = true;
|
|
137
133
|
|
|
138
134
|
this._verifyServerlessVersionCompatibility();
|
|
139
135
|
|
|
@@ -167,14 +163,14 @@ class ServerlessOffline {
|
|
|
167
163
|
}
|
|
168
164
|
|
|
169
165
|
async ready() {
|
|
170
|
-
if (
|
|
166
|
+
if (_process.env.NODE_ENV !== 'test') {
|
|
171
167
|
await this._listenForTermination();
|
|
172
168
|
}
|
|
173
169
|
}
|
|
174
170
|
|
|
175
171
|
async end(skipExit) {
|
|
176
172
|
// TEMP FIXME
|
|
177
|
-
if (
|
|
173
|
+
if (_process.env.NODE_ENV === 'test' && skipExit === undefined) {
|
|
178
174
|
return;
|
|
179
175
|
}
|
|
180
176
|
|
|
@@ -205,7 +201,7 @@ class ServerlessOffline {
|
|
|
205
201
|
await Promise.all(eventModules);
|
|
206
202
|
|
|
207
203
|
if (!skipExit) {
|
|
208
|
-
|
|
204
|
+
(0, _process.exit)(0);
|
|
209
205
|
}
|
|
210
206
|
}
|
|
211
207
|
|
|
@@ -231,7 +227,7 @@ class ServerlessOffline {
|
|
|
231
227
|
|
|
232
228
|
async _listenForTermination() {
|
|
233
229
|
const command = await new Promise(resolve => {
|
|
234
|
-
|
|
230
|
+
_process.default // SIGINT will be usually sent when user presses ctrl+c
|
|
235
231
|
.on('SIGINT', () => resolve('SIGINT')) // SIGTERM is a default termination signal in many cases,
|
|
236
232
|
// for example when "killing" a subprocess spawned in node
|
|
237
233
|
// with child_process methods
|
|
@@ -393,10 +389,15 @@ class ServerlessOffline {
|
|
|
393
389
|
httpEvent.http.method = '';
|
|
394
390
|
}
|
|
395
391
|
|
|
396
|
-
|
|
397
|
-
|
|
392
|
+
if (httpEvent.http.method === '*' && httpEvent.http.path === '*') {
|
|
393
|
+
httpEvent.http.routeKey = '$default';
|
|
394
|
+
} else {
|
|
395
|
+
const resolvedMethod = httpEvent.http.method === '*' ? 'ANY' : httpEvent.http.method.toUpperCase();
|
|
396
|
+
httpEvent.http.routeKey = `${resolvedMethod} ${httpEvent.http.path}`;
|
|
397
|
+
} // Clear these properties to avoid confusion (they will be derived from the routeKey
|
|
398
398
|
// when needed later)
|
|
399
399
|
|
|
400
|
+
|
|
400
401
|
delete httpEvent.http.method;
|
|
401
402
|
delete httpEvent.http.path;
|
|
402
403
|
} 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;
|
|
@@ -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
|