serverless-offline 8.7.0 → 9.0.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 +91 -95
- package/package.json +41 -69
- package/src/ServerlessOffline.js +412 -0
- package/src/config/commandOptions.js +155 -0
- package/src/config/constants.js +22 -0
- package/{dist → src}/config/defaultOptions.js +8 -17
- package/src/config/index.js +4 -0
- package/src/config/supportedRuntimes.js +47 -0
- package/src/events/authCanExecuteResource.js +35 -0
- package/src/events/authFunctionNameExtractor.js +75 -0
- package/src/events/authMatchPolicyResource.js +71 -0
- package/src/events/authValidateContext.js +51 -0
- package/src/events/http/Endpoint.js +135 -0
- package/src/events/http/Http.js +50 -0
- package/src/events/http/HttpEventDefinition.js +20 -0
- package/src/events/http/HttpServer.js +1277 -0
- package/src/events/http/OfflineEndpoint.js +33 -0
- package/src/events/http/authJWTSettingsExtractor.js +70 -0
- package/src/events/http/createAuthScheme.js +176 -0
- package/src/events/http/createJWTAuthScheme.js +106 -0
- package/src/events/http/index.js +1 -0
- package/src/events/http/javaHelpers.js +102 -0
- package/src/events/http/lambda-events/LambdaIntegrationEvent.js +57 -0
- package/src/events/http/lambda-events/LambdaProxyIntegrationEvent.js +233 -0
- package/src/events/http/lambda-events/LambdaProxyIntegrationEventV2.js +190 -0
- package/src/events/http/lambda-events/VelocityContext.js +147 -0
- package/src/events/http/lambda-events/index.js +4 -0
- package/src/events/http/lambda-events/renderVelocityTemplateObject.js +93 -0
- package/{dist → src}/events/http/parseResources.js +73 -78
- package/src/events/http/payloadSchemaValidator.js +13 -0
- package/{dist → src}/events/http/templates/offline-default.req.vm +0 -0
- package/{dist → src}/events/http/templates/offline-default.res.vm +0 -0
- package/src/events/schedule/Schedule.js +131 -0
- package/src/events/schedule/ScheduleEvent.js +18 -0
- package/src/events/schedule/ScheduleEventDefinition.js +21 -0
- package/src/events/schedule/index.js +1 -0
- package/src/events/websocket/HttpServer.js +69 -0
- package/src/events/websocket/WebSocket.js +52 -0
- package/src/events/websocket/WebSocketClients.js +462 -0
- package/src/events/websocket/WebSocketEventDefinition.js +18 -0
- package/src/events/websocket/WebSocketServer.js +73 -0
- package/src/events/websocket/http-routes/_catchAll/catchAllRoute.js +16 -0
- package/src/events/websocket/http-routes/_catchAll/index.js +1 -0
- package/src/events/websocket/http-routes/connections/ConnectionsController.js +28 -0
- package/src/events/websocket/http-routes/connections/connectionsRoutes.js +70 -0
- package/src/events/websocket/http-routes/connections/index.js +1 -0
- package/src/events/websocket/http-routes/index.js +2 -0
- package/src/events/websocket/index.js +1 -0
- package/src/events/websocket/lambda-events/WebSocketAuthorizerEvent.js +65 -0
- package/src/events/websocket/lambda-events/WebSocketConnectEvent.js +68 -0
- package/src/events/websocket/lambda-events/WebSocketDisconnectEvent.js +31 -0
- package/src/events/websocket/lambda-events/WebSocketEvent.js +29 -0
- package/src/events/websocket/lambda-events/WebSocketRequestContext.js +67 -0
- package/src/events/websocket/lambda-events/index.js +4 -0
- package/src/index.js +12 -0
- package/src/lambda/HttpServer.js +108 -0
- package/src/lambda/Lambda.js +68 -0
- package/src/lambda/LambdaContext.js +33 -0
- package/src/lambda/LambdaFunction.js +308 -0
- package/src/lambda/LambdaFunctionPool.js +109 -0
- package/src/lambda/__tests__/LambdaContext.test.js +30 -0
- package/src/lambda/__tests__/LambdaFunction.test.js +196 -0
- package/src/lambda/__tests__/fixtures/Lambda/LambdaFunctionThatReturnsJSONObject.fixture.js +47 -0
- package/src/lambda/__tests__/fixtures/Lambda/LambdaFunctionThatReturnsNativeString.fixture.js +46 -0
- package/src/lambda/__tests__/fixtures/Lambda/package.json +3 -0
- package/src/lambda/__tests__/fixtures/lambdaFunction.fixture.js +145 -0
- package/src/lambda/__tests__/fixtures/package.json +3 -0
- package/src/lambda/__tests__/routes/invocations/InvocationsController.test.js +42 -0
- package/src/lambda/handler-runner/HandlerRunner.js +136 -0
- package/src/lambda/handler-runner/child-process-runner/ChildProcessRunner.js +72 -0
- package/src/lambda/handler-runner/child-process-runner/childProcessHelper.js +42 -0
- package/src/lambda/handler-runner/child-process-runner/index.js +1 -0
- package/src/lambda/handler-runner/docker-runner/DockerContainer.js +417 -0
- package/src/lambda/handler-runner/docker-runner/DockerImage.js +35 -0
- package/src/lambda/handler-runner/docker-runner/DockerRunner.js +63 -0
- package/src/lambda/handler-runner/docker-runner/index.js +1 -0
- package/src/lambda/handler-runner/go-runner/GoRunner.js +166 -0
- package/src/lambda/handler-runner/go-runner/index.js +1 -0
- package/src/lambda/handler-runner/in-process-runner/InProcessRunner.js +125 -0
- package/src/lambda/handler-runner/in-process-runner/index.js +1 -0
- package/src/lambda/handler-runner/index.js +1 -0
- package/src/lambda/handler-runner/java-runner/JavaRunner.js +114 -0
- package/src/lambda/handler-runner/java-runner/index.js +1 -0
- package/src/lambda/handler-runner/python-runner/PythonRunner.js +138 -0
- package/src/lambda/handler-runner/python-runner/index.js +1 -0
- package/{dist → src}/lambda/handler-runner/python-runner/invoke.py +0 -0
- package/src/lambda/handler-runner/ruby-runner/RubyRunner.js +107 -0
- package/src/lambda/handler-runner/ruby-runner/index.js +1 -0
- package/{dist → src}/lambda/handler-runner/ruby-runner/invoke.rb +0 -0
- package/src/lambda/handler-runner/worker-thread-runner/WorkerThreadRunner.js +70 -0
- package/src/lambda/handler-runner/worker-thread-runner/index.js +1 -0
- package/src/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js +29 -0
- package/src/lambda/index.js +1 -0
- package/src/lambda/routes/index.js +2 -0
- package/src/lambda/routes/invocations/InvocationsController.js +102 -0
- package/src/lambda/routes/invocations/index.js +1 -0
- package/src/lambda/routes/invocations/invocationsRoute.js +77 -0
- package/src/lambda/routes/invoke-async/InvokeAsyncController.js +20 -0
- package/src/lambda/routes/invoke-async/index.js +1 -0
- package/src/lambda/routes/invoke-async/invokeAsyncRoute.js +33 -0
- package/src/utils/__tests__/createUniqueId.test.js +18 -0
- package/src/utils/__tests__/formatToClfTime.test.js +14 -0
- package/src/utils/__tests__/generateHapiPath.test.js +46 -0
- package/src/utils/__tests__/lowerCaseKeys.test.js +30 -0
- package/src/utils/__tests__/parseHeaders.test.js +13 -0
- package/src/utils/__tests__/parseMultiValueHeaders.test.js +24 -0
- package/src/utils/__tests__/parseMultiValueQueryStringParameters.test.js +159 -0
- package/src/utils/__tests__/parseQueryStringParameters.test.js +15 -0
- package/src/utils/__tests__/splitHandlerPathAndName.test.js +54 -0
- package/src/utils/__tests__/unflatten.test.js +32 -0
- package/src/utils/checkDockerDaemon.js +19 -0
- package/src/utils/checkGoVersion.js +16 -0
- package/src/utils/createApiKey.js +5 -0
- package/src/utils/createUniqueId.js +5 -0
- package/src/utils/detectExecutable.js +11 -0
- package/{dist → src}/utils/formatToClfTime.js +6 -14
- package/src/utils/generateHapiPath.js +26 -0
- package/src/utils/getHttpApiCorsConfig.js +28 -0
- package/src/utils/index.js +42 -0
- package/src/utils/jsonPath.js +13 -0
- package/src/utils/logRoutes.js +64 -0
- package/src/utils/lowerCaseKeys.js +6 -0
- package/src/utils/parseHeaders.js +14 -0
- package/src/utils/parseMultiValueHeaders.js +27 -0
- package/src/utils/parseMultiValueQueryStringParameters.js +31 -0
- package/src/utils/parseQueryStringParameters.js +15 -0
- package/src/utils/resolveJoins.js +29 -0
- package/src/utils/splitHandlerPathAndName.js +31 -0
- package/src/utils/unflatten.js +11 -0
- package/dist/ServerlessOffline.js +0 -507
- package/dist/checkEngine.js +0 -21
- package/dist/config/commandOptions.js +0 -149
- package/dist/config/constants.js +0 -30
- package/dist/config/index.js +0 -55
- package/dist/config/supportedRuntimes.js +0 -40
- package/dist/debugLog.js +0 -10
- package/dist/events/authCanExecuteResource.js +0 -35
- package/dist/events/authFunctionNameExtractor.js +0 -87
- package/dist/events/authMatchPolicyResource.js +0 -62
- package/dist/events/http/Endpoint.js +0 -171
- package/dist/events/http/Http.js +0 -77
- package/dist/events/http/HttpEventDefinition.js +0 -36
- package/dist/events/http/HttpServer.js +0 -1363
- package/dist/events/http/OfflineEndpoint.js +0 -40
- package/dist/events/http/authJWTSettingsExtractor.js +0 -76
- package/dist/events/http/authValidateContext.js +0 -48
- package/dist/events/http/createAuthScheme.js +0 -184
- package/dist/events/http/createJWTAuthScheme.js +0 -155
- package/dist/events/http/index.js +0 -15
- package/dist/events/http/javaHelpers.js +0 -99
- package/dist/events/http/lambda-events/LambdaIntegrationEvent.js +0 -85
- package/dist/events/http/lambda-events/LambdaProxyIntegrationEvent.js +0 -244
- package/dist/events/http/lambda-events/LambdaProxyIntegrationEventV2.js +0 -221
- package/dist/events/http/lambda-events/VelocityContext.js +0 -168
- package/dist/events/http/lambda-events/index.js +0 -39
- package/dist/events/http/lambda-events/renderVelocityTemplateObject.js +0 -108
- package/dist/events/http/payloadSchemaValidator.js +0 -13
- package/dist/events/schedule/Schedule.js +0 -182
- package/dist/events/schedule/ScheduleEvent.js +0 -27
- package/dist/events/schedule/ScheduleEventDefinition.js +0 -36
- package/dist/events/schedule/index.js +0 -15
- package/dist/events/websocket/HttpServer.js +0 -112
- package/dist/events/websocket/WebSocket.js +0 -78
- package/dist/events/websocket/WebSocketClients.js +0 -550
- package/dist/events/websocket/WebSocketEventDefinition.js +0 -32
- package/dist/events/websocket/WebSocketServer.js +0 -140
- package/dist/events/websocket/http-routes/_catchAll/catchAllRoute.js +0 -33
- package/dist/events/websocket/http-routes/_catchAll/index.js +0 -15
- package/dist/events/websocket/http-routes/connections/ConnectionsController.js +0 -45
- package/dist/events/websocket/http-routes/connections/connectionsRoutes.js +0 -95
- package/dist/events/websocket/http-routes/connections/index.js +0 -15
- package/dist/events/websocket/http-routes/index.js +0 -23
- package/dist/events/websocket/index.js +0 -15
- package/dist/events/websocket/lambda-events/WebSocketAuthorizerEvent.js +0 -99
- package/dist/events/websocket/lambda-events/WebSocketConnectEvent.js +0 -101
- package/dist/events/websocket/lambda-events/WebSocketDisconnectEvent.js +0 -47
- package/dist/events/websocket/lambda-events/WebSocketEvent.js +0 -54
- package/dist/events/websocket/lambda-events/WebSocketRequestContext.js +0 -98
- package/dist/events/websocket/lambda-events/index.js +0 -39
- package/dist/index.js +0 -19
- package/dist/lambda/HttpServer.js +0 -122
- package/dist/lambda/Lambda.js +0 -113
- package/dist/lambda/LambdaContext.js +0 -53
- package/dist/lambda/LambdaFunction.js +0 -391
- package/dist/lambda/LambdaFunctionPool.js +0 -127
- package/dist/lambda/handler-runner/HandlerRunner.js +0 -223
- package/dist/lambda/handler-runner/child-process-runner/ChildProcessRunner.js +0 -132
- package/dist/lambda/handler-runner/child-process-runner/childProcessHelper.js +0 -40
- package/dist/lambda/handler-runner/child-process-runner/index.js +0 -15
- package/dist/lambda/handler-runner/docker-runner/DockerContainer.js +0 -517
- package/dist/lambda/handler-runner/docker-runner/DockerImage.js +0 -67
- package/dist/lambda/handler-runner/docker-runner/DockerRunner.js +0 -74
- package/dist/lambda/handler-runner/docker-runner/index.js +0 -15
- package/dist/lambda/handler-runner/go-runner/GoRunner.js +0 -211
- package/dist/lambda/handler-runner/go-runner/index.js +0 -15
- package/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js +0 -234
- package/dist/lambda/handler-runner/in-process-runner/index.js +0 -15
- package/dist/lambda/handler-runner/index.js +0 -15
- package/dist/lambda/handler-runner/java-runner/JavaRunner.js +0 -151
- package/dist/lambda/handler-runner/java-runner/index.js +0 -15
- package/dist/lambda/handler-runner/python-runner/PythonRunner.js +0 -180
- package/dist/lambda/handler-runner/python-runner/index.js +0 -15
- package/dist/lambda/handler-runner/ruby-runner/RubyRunner.js +0 -148
- package/dist/lambda/handler-runner/ruby-runner/index.js +0 -15
- package/dist/lambda/handler-runner/worker-thread-runner/WorkerThreadRunner.js +0 -94
- package/dist/lambda/handler-runner/worker-thread-runner/index.js +0 -15
- package/dist/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js +0 -30
- package/dist/lambda/index.js +0 -15
- package/dist/lambda/routes/index.js +0 -23
- package/dist/lambda/routes/invocations/InvocationsController.js +0 -142
- package/dist/lambda/routes/invocations/index.js +0 -15
- package/dist/lambda/routes/invocations/invocationsRoute.js +0 -90
- package/dist/lambda/routes/invoke-async/InvokeAsyncController.js +0 -38
- package/dist/lambda/routes/invoke-async/index.js +0 -15
- package/dist/lambda/routes/invoke-async/invokeAsyncRoute.js +0 -43
- package/dist/main.js +0 -11
- package/dist/serverlessLog.js +0 -91
- package/dist/utils/checkDockerDaemon.js +0 -27
- package/dist/utils/checkGoVersion.js +0 -27
- package/dist/utils/createApiKey.js +0 -12
- package/dist/utils/createUniqueId.js +0 -14
- package/dist/utils/detectExecutable.js +0 -21
- package/dist/utils/generateHapiPath.js +0 -28
- package/dist/utils/getHttpApiCorsConfig.js +0 -44
- package/dist/utils/index.js +0 -158
- package/dist/utils/jsonPath.js +0 -21
- package/dist/utils/parseHeaders.js +0 -23
- package/dist/utils/parseMultiValueHeaders.js +0 -36
- package/dist/utils/parseMultiValueQueryStringParameters.js +0 -40
- package/dist/utils/parseQueryStringParameters.js +0 -26
- package/dist/utils/resolveJoins.js +0 -34
- package/dist/utils/satisfiesVersionRange.js +0 -20
- package/dist/utils/splitHandlerPathAndName.js +0 -41
- package/dist/utils/unflatten.js +0 -18
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)
|
|
@@ -90,7 +89,7 @@ plugins:
|
|
|
90
89
|
- serverless-offline
|
|
91
90
|
```
|
|
92
91
|
|
|
93
|
-
You can check
|
|
92
|
+
You can check whether you have successfully installed the plugin by running the serverless command line:
|
|
94
93
|
|
|
95
94
|
`serverless --verbose`
|
|
96
95
|
|
|
@@ -109,7 +108,6 @@ to list all the options for the plugin run:
|
|
|
109
108
|
All CLI options are optional:
|
|
110
109
|
|
|
111
110
|
```
|
|
112
|
-
--allowCache Allows the code of lambda functions to cache if supported.
|
|
113
111
|
--apiKey Defines the API key value to be used for endpoints marked as private Defaults to a random hash.
|
|
114
112
|
--corsAllowHeaders Used as default Access-Control-Allow-Headers header value for responses. Delimit multiple values with commas. Default: 'accept,content-type,x-api-key'
|
|
115
113
|
--corsAllowOrigin Used as default Access-Control-Allow-Origin header value for responses. Delimit multiple values with commas. Default: '*'
|
|
@@ -135,10 +133,11 @@ All CLI options are optional:
|
|
|
135
133
|
--noTimeout -t Disables the timeout feature.
|
|
136
134
|
--prefix -p Adds a prefix to every path, to send your requests to http://localhost:3000/[prefix]/[your_path] instead. Default: ''
|
|
137
135
|
--printOutput Turns on logging of your lambda outputs in the terminal.
|
|
136
|
+
--reloadHandler Reloads handler with each request.
|
|
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
|
-
--
|
|
140
|
+
--useInProcess Run handlers in the same process as 'serverless-offline'.
|
|
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) |
|
package/package.json
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dedicatedTo": "Blue, a great migrating bird.",
|
|
3
3
|
"name": "serverless-offline",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "9.0.0",
|
|
5
5
|
"description": "Emulate AWS λ and API Gateway locally when developing your Serverless project",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"main": "
|
|
8
|
-
"
|
|
7
|
+
"main": "./src/index.js",
|
|
8
|
+
"exports": "./src/index.js",
|
|
9
|
+
"type": "module",
|
|
9
10
|
"scripts": {
|
|
10
|
-
"build": "rimraf dist && babel src --ignore \"**/__tests__/**/*\" --out-dir dist && copyfiles -u 1 \"src/**/*.{vm,py,rb}\" dist",
|
|
11
11
|
"format": "eslint . --fix",
|
|
12
12
|
"lint": "eslint .",
|
|
13
13
|
"lint:updated": "pipe-git-updated --ext=js -- eslint",
|
|
14
14
|
"list-contributors": "echo 'clone https://github.com/mgechev/github-contributors-list.git first, then run npm install' && cd ../github-contributors-list && node bin/githubcontrib --owner dherault --repo serverless-offline --sortBy contributions --showlogin true --sortOrder desc > contributors.md",
|
|
15
|
-
"prepare": "
|
|
15
|
+
"prepare": "husky install",
|
|
16
16
|
"prepare-release": "standard-version && prettier --write CHANGELOG.md",
|
|
17
|
-
"prepublishOnly": "npm run lint
|
|
17
|
+
"prepublishOnly": "npm run lint",
|
|
18
18
|
"prettier-check": "prettier -c --ignore-path .gitignore \"**/*.{css,html,js,json,md,yaml,yml}\"",
|
|
19
19
|
"prettier-check:updated": "pipe-git-updated --ext=css --ext=html --ext=js --ext=json --ext=md --ext=yaml --ext=yml -- prettier -c",
|
|
20
20
|
"prettify": "prettier --write --ignore-path .gitignore \"**/*.{css,html,js,json,md,yaml,yml}\"",
|
|
21
21
|
"prettify:updated": "pipe-git-updated --ext=css --ext=html --ext=js --ext=json --ext=md --ext=yaml --ext=yml -- prettier --write",
|
|
22
|
-
"test": "
|
|
22
|
+
"test": "mocha --require ./tests/mochaHooks.cjs",
|
|
23
|
+
"test:jest": "npm run build && jest --verbose --silent --runInBand",
|
|
23
24
|
"test:cov": "npm run build && jest --coverage --silent --runInBand --collectCoverageFrom=src/**/*.js",
|
|
24
25
|
"test:log": "npm run build && jest --verbose",
|
|
25
26
|
"test:noBuild": "jest --verbose --runInBand --bail",
|
|
@@ -49,7 +50,7 @@
|
|
|
49
50
|
"websocket"
|
|
50
51
|
],
|
|
51
52
|
"files": [
|
|
52
|
-
"
|
|
53
|
+
"src/**",
|
|
53
54
|
"package.json",
|
|
54
55
|
"LICENSE",
|
|
55
56
|
"README.md"
|
|
@@ -118,6 +119,7 @@
|
|
|
118
119
|
"kobanyan (https://github.com/kobanyan)",
|
|
119
120
|
"Leonardo Alifraco (https://github.com/lalifraco-devspark)",
|
|
120
121
|
"Leonardo Medici (https://github.com/doclm)",
|
|
122
|
+
"Luciano Jesus Lima (https://github.com/brazilianbytes)",
|
|
121
123
|
"Luke Chavers (https://github.com/vmadman)",
|
|
122
124
|
"Manuel Böhm (https://github.com/boehmers)",
|
|
123
125
|
"Marc Campbell (https://github.com/marccampbell)",
|
|
@@ -161,21 +163,8 @@
|
|
|
161
163
|
"Fernando Alvarez (https://github.com/jefer590)",
|
|
162
164
|
"Eric Carter (https://github.com/ericctsf)"
|
|
163
165
|
],
|
|
164
|
-
"husky": {
|
|
165
|
-
"hooks": {
|
|
166
|
-
"pre-commit": "lint-staged"
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
"lint-staged": {
|
|
170
|
-
"*.js": [
|
|
171
|
-
"eslint"
|
|
172
|
-
],
|
|
173
|
-
"*.{css,html,js,json,md,yaml,yml}": [
|
|
174
|
-
"prettier -c"
|
|
175
|
-
]
|
|
176
|
-
},
|
|
177
166
|
"engines": {
|
|
178
|
-
"node": ">=
|
|
167
|
+
"node": ">=14.18.0"
|
|
179
168
|
},
|
|
180
169
|
"standard-version": {
|
|
181
170
|
"skip": {
|
|
@@ -202,63 +191,46 @@
|
|
|
202
191
|
]
|
|
203
192
|
},
|
|
204
193
|
"dependencies": {
|
|
205
|
-
"@hapi/boom": "^
|
|
194
|
+
"@hapi/boom": "^10.0.0",
|
|
206
195
|
"@hapi/h2o2": "^9.1.0",
|
|
207
|
-
"@hapi/hapi": "^20.2.
|
|
208
|
-
"aws-sdk": "^2.
|
|
209
|
-
"boxen": "^
|
|
210
|
-
"chalk": "^
|
|
211
|
-
"
|
|
212
|
-
"
|
|
213
|
-
"extend": "^3.0.2",
|
|
214
|
-
"fs-extra": "^9.1.0",
|
|
196
|
+
"@hapi/hapi": "^20.2.2",
|
|
197
|
+
"aws-sdk": "^2.1176.0",
|
|
198
|
+
"boxen": "^7.0.0",
|
|
199
|
+
"chalk": "^5.0.1",
|
|
200
|
+
"execa": "^6.1.0",
|
|
201
|
+
"fs-extra": "^10.1.0",
|
|
215
202
|
"java-invoke-local": "0.0.6",
|
|
216
203
|
"js-string-escape": "^1.0.1",
|
|
217
|
-
"jsonpath-plus": "^
|
|
218
|
-
"jsonschema": "^1.4.
|
|
204
|
+
"jsonpath-plus": "^7.0.0",
|
|
205
|
+
"jsonschema": "^1.4.1",
|
|
219
206
|
"jsonwebtoken": "^8.5.1",
|
|
220
|
-
"jszip": "^3.
|
|
221
|
-
"luxon": "^
|
|
222
|
-
"node-fetch": "^2.
|
|
223
|
-
"node-schedule": "^1.
|
|
224
|
-
"object.
|
|
225
|
-
"p-memoize": "^
|
|
226
|
-
"p-
|
|
227
|
-
"p-retry": "^4.6.1",
|
|
228
|
-
"please-upgrade-node": "^3.2.0",
|
|
229
|
-
"semver": "^7.3.5",
|
|
230
|
-
"update-notifier": "^5.1.0",
|
|
207
|
+
"jszip": "^3.10.0",
|
|
208
|
+
"luxon": "^3.0.1",
|
|
209
|
+
"node-fetch": "^3.2.8",
|
|
210
|
+
"node-schedule": "^2.1.0",
|
|
211
|
+
"object.hasown": "^1.1.1",
|
|
212
|
+
"p-memoize": "^7.1.0",
|
|
213
|
+
"p-retry": "^5.1.1",
|
|
231
214
|
"velocityjs": "^2.0.6",
|
|
232
|
-
"ws": "^
|
|
215
|
+
"ws": "^8.8.1"
|
|
233
216
|
},
|
|
234
217
|
"devDependencies": {
|
|
235
|
-
"
|
|
236
|
-
"
|
|
237
|
-
"
|
|
238
|
-
"
|
|
239
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.7",
|
|
240
|
-
"@babel/plugin-proposal-optional-chaining": "^7.16.7",
|
|
241
|
-
"@babel/plugin-transform-modules-commonjs": "^7.17.7",
|
|
242
|
-
"@babel/register": "^7.17.7",
|
|
243
|
-
"archiver": "^5.3.0",
|
|
244
|
-
"babel-eslint": "^10.1.0",
|
|
245
|
-
"copyfiles": "^2.4.1",
|
|
246
|
-
"eslint": "^7.32.0",
|
|
247
|
-
"eslint-config-airbnb-base": "^14.2.1",
|
|
248
|
-
"eslint-config-prettier": "^7.2.0",
|
|
218
|
+
"archiver": "^5.3.1",
|
|
219
|
+
"eslint": "^8.20.0",
|
|
220
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
221
|
+
"eslint-config-prettier": "^8.5.0",
|
|
249
222
|
"eslint-plugin-import": "^2.25.4",
|
|
250
|
-
"eslint-plugin-prettier": "^
|
|
223
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
251
224
|
"git-list-updated": "^1.2.1",
|
|
252
|
-
"husky": "^
|
|
253
|
-
"
|
|
254
|
-
"
|
|
255
|
-
"
|
|
256
|
-
"
|
|
257
|
-
"
|
|
258
|
-
"serverless": "^2.72.3",
|
|
259
|
-
"standard-version": "^9.3.2"
|
|
225
|
+
"husky": "^8.0.1",
|
|
226
|
+
"lint-staged": "^13.0.3",
|
|
227
|
+
"mocha": "^10.0.0",
|
|
228
|
+
"prettier": "^2.7.1",
|
|
229
|
+
"serverless": "^3.21.0",
|
|
230
|
+
"standard-version": "^9.5.0"
|
|
260
231
|
},
|
|
261
232
|
"peerDependencies": {
|
|
262
|
-
"serverless": "^
|
|
233
|
+
"@serverless/utils": "^6.7.0",
|
|
234
|
+
"serverless": "^3.2.0"
|
|
263
235
|
}
|
|
264
236
|
}
|