serverless-offline 8.8.1 → 9.1.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/README.md +112 -44
- package/package.json +33 -57
- package/src/ServerlessOffline.js +409 -0
- package/src/config/commandOptions.js +159 -0
- package/src/config/constants.js +22 -0
- package/{dist → src}/config/defaultOptions.js +9 -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 +1242 -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 +309 -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 +76 -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 +419 -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 +172 -0
- package/src/lambda/handler-runner/go-runner/index.js +1 -0
- package/src/lambda/handler-runner/in-process-runner/InProcessRunner.js +126 -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/splitHandlerPathAndName.js +31 -0
- package/src/utils/unflatten.js +11 -0
- package/CHANGELOG.md +0 -78
- package/dist/ServerlessOffline.js +0 -508
- 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 -12
- package/dist/events/authCanExecuteResource.js +0 -35
- package/dist/events/authFunctionNameExtractor.js +0 -87
- package/dist/events/authMatchPolicyResource.js +0 -62
- package/dist/events/authValidateContext.js +0 -53
- package/dist/events/http/Endpoint.js +0 -173
- package/dist/events/http/Http.js +0 -77
- package/dist/events/http/HttpEventDefinition.js +0 -36
- package/dist/events/http/HttpServer.js +0 -1370
- package/dist/events/http/OfflineEndpoint.js +0 -38
- package/dist/events/http/authJWTSettingsExtractor.js +0 -76
- package/dist/events/http/createAuthScheme.js +0 -184
- package/dist/events/http/createJWTAuthScheme.js +0 -159
- 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 -87
- package/dist/events/http/lambda-events/LambdaProxyIntegrationEvent.js +0 -246
- package/dist/events/http/lambda-events/LambdaProxyIntegrationEventV2.js +0 -225
- package/dist/events/http/lambda-events/VelocityContext.js +0 -170
- package/dist/events/http/lambda-events/index.js +0 -39
- package/dist/events/http/lambda-events/renderVelocityTemplateObject.js +0 -111
- package/dist/events/http/payloadSchemaValidator.js +0 -13
- package/dist/events/schedule/Schedule.js +0 -183
- 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 -114
- package/dist/events/websocket/WebSocket.js +0 -78
- package/dist/events/websocket/WebSocketClients.js +0 -577
- package/dist/events/websocket/WebSocketEventDefinition.js +0 -32
- package/dist/events/websocket/WebSocketServer.js +0 -139
- 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 -15
- package/dist/lambda/HttpServer.js +0 -124
- package/dist/lambda/Lambda.js +0 -117
- package/dist/lambda/LambdaContext.js +0 -53
- package/dist/lambda/LambdaFunction.js +0 -390
- package/dist/lambda/LambdaFunctionPool.js +0 -127
- package/dist/lambda/handler-runner/HandlerRunner.js +0 -195
- package/dist/lambda/handler-runner/child-process-runner/ChildProcessRunner.js +0 -124
- package/dist/lambda/handler-runner/child-process-runner/childProcessHelper.js +0 -49
- package/dist/lambda/handler-runner/child-process-runner/index.js +0 -15
- package/dist/lambda/handler-runner/docker-runner/DockerContainer.js +0 -515
- 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 -230
- package/dist/lambda/handler-runner/go-runner/index.js +0 -15
- package/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js +0 -228
- 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 -153
- package/dist/lambda/handler-runner/java-runner/index.js +0 -15
- package/dist/lambda/handler-runner/python-runner/PythonRunner.js +0 -185
- package/dist/lambda/handler-runner/python-runner/index.js +0 -15
- package/dist/lambda/handler-runner/ruby-runner/RubyRunner.js +0 -147
- package/dist/lambda/handler-runner/ruby-runner/index.js +0 -15
- package/dist/lambda/handler-runner/worker-thread-runner/WorkerThreadRunner.js +0 -92
- package/dist/lambda/handler-runner/worker-thread-runner/index.js +0 -15
- package/dist/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js +0 -31
- 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 -40
- package/dist/utils/index.js +0 -165
- package/dist/utils/jsonPath.js +0 -21
- package/dist/utils/lowerCaseKeys.js +0 -14
- 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 -36
- package/dist/utils/satisfiesVersionRange.js +0 -20
- package/dist/utils/splitHandlerPathAndName.js +0 -37
- package/dist/utils/unflatten.js +0 -18
package/README.md
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
<a href="https://www.npmjs.com/package/serverless-offline">
|
|
8
8
|
<img src="https://img.shields.io/npm/v/serverless-offline.svg?style=flat-square">
|
|
9
9
|
</a>
|
|
10
|
-
<a href="https://github.com/dherault/serverless-offline/actions
|
|
11
|
-
<img src="https://img.shields.io/github/workflow/status/dherault/serverless-offline/
|
|
10
|
+
<a href="https://github.com/dherault/serverless-offline/actions/workflows/integrate.yml">
|
|
11
|
+
<img src="https://img.shields.io/github/workflow/status/dherault/serverless-offline/Integrate">
|
|
12
12
|
</a>
|
|
13
13
|
<img src="https://img.shields.io/node/v/serverless-offline.svg?style=flat-square">
|
|
14
14
|
<a href="https://github.com/serverless/serverless">
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
This [Serverless](https://github.com/serverless/serverless) plugin emulates [AWS λ](https://aws.amazon.com/lambda) and [API Gateway](https://aws.amazon.com/api-gateway) on your local machine to speed up your development cycles.
|
|
30
30
|
To do so, it starts an HTTP server that handles the request's lifecycle like APIG does and invokes your handlers.
|
|
31
31
|
|
|
32
|
-
**Features
|
|
32
|
+
**Features**
|
|
33
33
|
|
|
34
|
-
- [Node.js](https://nodejs.org), [Python](https://www.python.org), [Ruby](https://www.ruby-lang.org)
|
|
34
|
+
- [Node.js](https://nodejs.org), [Python](https://www.python.org), [Ruby](https://www.ruby-lang.org), [Go](https://golang.org), [Java](https://www.java.com) (incl. [Kotlin](https://kotlinlang.org), [Groovy](https://groovy-lang.org), [Scala](https://www.scala-lang.org)) λ runtimes.
|
|
35
35
|
- Velocity templates support.
|
|
36
36
|
- Lazy loading of your handler files.
|
|
37
37
|
- And more: integrations, authorizers, proxies, timeouts, responseParameters, HTTPS, CORS, etc...
|
|
@@ -42,6 +42,7 @@ This plugin is updated by its users, I just do maintenance and ensure that PRs a
|
|
|
42
42
|
|
|
43
43
|
- [Installation](#installation)
|
|
44
44
|
- [Usage and command line options](#usage-and-command-line-options)
|
|
45
|
+
- [Run modes](#run-modes)
|
|
45
46
|
- [Usage with `invoke`](#usage-with-invoke)
|
|
46
47
|
- [The `process.env.IS_OFFLINE` variable](#the-processenvis_offline-variable)
|
|
47
48
|
- [Docker and Layers](#docker-and-layers)
|
|
@@ -84,12 +85,12 @@ Then inside your project's `serverless.yml` file add following entry to the plug
|
|
|
84
85
|
|
|
85
86
|
It should look something like this:
|
|
86
87
|
|
|
87
|
-
```
|
|
88
|
+
```yml
|
|
88
89
|
plugins:
|
|
89
90
|
- serverless-offline
|
|
90
91
|
```
|
|
91
92
|
|
|
92
|
-
You can check
|
|
93
|
+
You can check whether you have successfully installed the plugin by running the serverless command line:
|
|
93
94
|
|
|
94
95
|
`serverless --verbose`
|
|
95
96
|
|
|
@@ -108,7 +109,6 @@ to list all the options for the plugin run:
|
|
|
108
109
|
All CLI options are optional:
|
|
109
110
|
|
|
110
111
|
```
|
|
111
|
-
--allowCache Allows the code of lambda functions to cache if supported.
|
|
112
112
|
--apiKey Defines the API key value to be used for endpoints marked as private Defaults to a random hash.
|
|
113
113
|
--corsAllowHeaders Used as default Access-Control-Allow-Headers header value for responses. Delimit multiple values with commas. Default: 'accept,content-type,x-api-key'
|
|
114
114
|
--corsAllowOrigin Used as default Access-Control-Allow-Origin header value for responses. Delimit multiple values with commas. Default: '*'
|
|
@@ -128,16 +128,18 @@ All CLI options are optional:
|
|
|
128
128
|
--ignoreJWTSignature When using HttpApi with a JWT authorizer, don't check the signature of the JWT token. This should only be used for local development.
|
|
129
129
|
--lambdaPort Lambda http port to listen on. Default: 3002
|
|
130
130
|
--layersDir The directory layers should be stored in. Default: ${codeDir}/.serverless-offline/layers'
|
|
131
|
+
--localEnvironment Copy local environment variables. Default: false
|
|
131
132
|
--noAuth Turns off all authorizers
|
|
132
133
|
--noPrependStageInUrl Don't prepend http routes with the stage.
|
|
133
134
|
--noStripTrailingSlashInUrl Don't strip trailing slash from http routes.
|
|
134
135
|
--noTimeout -t Disables the timeout feature.
|
|
135
136
|
--prefix -p Adds a prefix to every path, to send your requests to http://localhost:3000/[prefix]/[your_path] instead. Default: ''
|
|
136
137
|
--printOutput Turns on logging of your lambda outputs in the terminal.
|
|
138
|
+
--reloadHandler Reloads handler with each request.
|
|
137
139
|
--resourceRoutes Turns on loading of your HTTP proxy settings from serverless.yml
|
|
138
140
|
--useChildProcesses Run handlers in a child process
|
|
139
141
|
--useDocker Run handlers in a docker container.
|
|
140
|
-
--
|
|
142
|
+
--useInProcess Run handlers in the same process as 'serverless-offline'.
|
|
141
143
|
--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)
|
|
142
144
|
--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)
|
|
143
145
|
--websocketPort WebSocket port to listen on. Default: 3001
|
|
@@ -145,13 +147,13 @@ All CLI options are optional:
|
|
|
145
147
|
|
|
146
148
|
Any of the CLI options can be added to your `serverless.yml`. For example:
|
|
147
149
|
|
|
148
|
-
```
|
|
150
|
+
```yml
|
|
149
151
|
custom:
|
|
150
152
|
serverless-offline:
|
|
151
|
-
httpsProtocol:
|
|
153
|
+
httpsProtocol: 'dev-certs'
|
|
152
154
|
httpPort: 4000
|
|
153
155
|
stageVariables:
|
|
154
|
-
foo:
|
|
156
|
+
foo: 'bar'
|
|
155
157
|
```
|
|
156
158
|
|
|
157
159
|
Options passed on the command line override YAML options.
|
|
@@ -163,18 +165,64 @@ By default you can send your requests to `http://localhost:3000/`. Please note t
|
|
|
163
165
|
But if you send an `application/x-www-form-urlencoded` or a `multipart/form-data` body with an `application/json` (or no) Content-Type, API Gateway won't parse your data (you'll get the ugly raw as input), whereas the plugin will answer 400 (malformed JSON).
|
|
164
166
|
Please consider explicitly setting your requests' Content-Type and using separate templates.
|
|
165
167
|
|
|
168
|
+
## Run modes
|
|
169
|
+
|
|
170
|
+
### node.js
|
|
171
|
+
|
|
172
|
+
Lambda handlers for the `node.js` runtime can run in different execution modes with `serverless-offline` and they have subtle differences with a variety of pros and cons. they are mutually exclusive and it is planned to combine the flags into one single flag in the future.
|
|
173
|
+
|
|
174
|
+
#### worker-threads (default)
|
|
175
|
+
|
|
176
|
+
- handlers run in their own context
|
|
177
|
+
- memory is not being shared between handlers, memory consumption is therefore higher
|
|
178
|
+
- memory is being released when handlers reload or after usage
|
|
179
|
+
- environment (process.env) is not being shared across handlers
|
|
180
|
+
- global state is not being shared across handlers
|
|
181
|
+
- easy debugging
|
|
182
|
+
|
|
183
|
+
#### in-process
|
|
184
|
+
|
|
185
|
+
- handlers run in the same context (instance) as `serverless` and `serverless-offline`
|
|
186
|
+
- memory is being shared across lambda handlers as well as with `serverless` and `serverless-offline`
|
|
187
|
+
- no reloading capabilities as it is [currently] not possible to implement for commonjs handlers (without memory leaks) and for esm handlers
|
|
188
|
+
- environment (process.env) is being shared across handlers as well as with `serverless` and `serverless-offline`
|
|
189
|
+
- global state is being shared across lambda handlers as well as with `serverless` and `serverless-offline`
|
|
190
|
+
- easy debugging
|
|
191
|
+
|
|
192
|
+
#### child-processes
|
|
193
|
+
|
|
194
|
+
- handlers run in a separate node.js instance
|
|
195
|
+
- memory is not being shared between handlers, memory consumption is therefore higher
|
|
196
|
+
- memory is being released when handlers reload or after usage
|
|
197
|
+
- environment (process.env) is not being shared across handlers
|
|
198
|
+
- global state is not being shared across handlers
|
|
199
|
+
- debugging more complicated
|
|
200
|
+
|
|
201
|
+
#### docker
|
|
202
|
+
|
|
203
|
+
- handlers run in a docker container
|
|
204
|
+
- memory is not being shared between handlers, memory consumption is therefore higher
|
|
205
|
+
- memory is being released when handlers reload or after usage
|
|
206
|
+
- environment (process.env) is not being shared across handlers
|
|
207
|
+
- global state is not being shared across handlers
|
|
208
|
+
- debugging more complicated
|
|
209
|
+
|
|
210
|
+
### Python, Ruby, Go, Java (incl. Kotlin, Groovy, Scala)
|
|
211
|
+
|
|
212
|
+
the Lambda handler process is running in a child process.
|
|
213
|
+
|
|
166
214
|
## Usage with `invoke`
|
|
167
215
|
|
|
168
|
-
To use `Lambda.invoke` you need to set the lambda endpoint to the serverless-offline endpoint:
|
|
216
|
+
To use `Lambda.invoke` you need to set the lambda endpoint to the `serverless-offline` endpoint:
|
|
169
217
|
|
|
170
218
|
```js
|
|
219
|
+
const { env } = require('node:process')
|
|
171
220
|
const { Lambda } = require('aws-sdk')
|
|
172
221
|
|
|
173
222
|
const lambda = new Lambda({
|
|
174
223
|
apiVersion: '2015-03-31',
|
|
175
|
-
// endpoint needs to be set only if it deviates from the default
|
|
176
|
-
|
|
177
|
-
endpoint: process.env.SOME_VARIABLE
|
|
224
|
+
// endpoint needs to be set only if it deviates from the default
|
|
225
|
+
endpoint: env.IS_OFFLINE
|
|
178
226
|
? 'http://localhost:3002'
|
|
179
227
|
: 'https://lambda.us-east-1.amazonaws.com',
|
|
180
228
|
})
|
|
@@ -183,15 +231,33 @@ const lambda = new Lambda({
|
|
|
183
231
|
All your lambdas can then be invoked in a handler using
|
|
184
232
|
|
|
185
233
|
```js
|
|
234
|
+
const { Buffer } = require('node:buffer')
|
|
235
|
+
const { Lambda } = require('aws-sdk')
|
|
236
|
+
|
|
237
|
+
const { stringify } = JSON
|
|
238
|
+
|
|
239
|
+
const lambda = new Lambda({
|
|
240
|
+
apiVersion: '2015-03-31',
|
|
241
|
+
endpoint: 'http://localhost:3002',
|
|
242
|
+
})
|
|
243
|
+
|
|
186
244
|
exports.handler = async function () {
|
|
245
|
+
const clientContextData = stringify({ foo: 'foo' })
|
|
246
|
+
|
|
187
247
|
const params = {
|
|
248
|
+
ClientContext: Buffer.from(clientContextData).toString('base64'),
|
|
188
249
|
// FunctionName is composed of: service name - stage - function name, e.g.
|
|
189
250
|
FunctionName: 'myServiceName-dev-invokedHandler',
|
|
190
251
|
InvocationType: 'RequestResponse',
|
|
191
|
-
Payload:
|
|
252
|
+
Payload: stringify({ data: 'foo' }),
|
|
192
253
|
}
|
|
193
254
|
|
|
194
255
|
const response = await lambda.invoke(params).promise()
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
body: stringify(response),
|
|
259
|
+
statusCode: 200,
|
|
260
|
+
}
|
|
195
261
|
}
|
|
196
262
|
```
|
|
197
263
|
|
|
@@ -243,7 +309,7 @@ to calling it via `aws-sdk`.
|
|
|
243
309
|
|
|
244
310
|
## The `process.env.IS_OFFLINE` variable
|
|
245
311
|
|
|
246
|
-
Will be `"true"` in your handlers
|
|
312
|
+
Will be `"true"` in your handlers when using `serverless-offline`.
|
|
247
313
|
|
|
248
314
|
## Docker and Layers
|
|
249
315
|
|
|
@@ -266,14 +332,14 @@ If you're using least-privilege principals for your AWS roles, this policy shoul
|
|
|
266
332
|
|
|
267
333
|
```json
|
|
268
334
|
{
|
|
269
|
-
"Version": "2012-10-17",
|
|
270
335
|
"Statement": [
|
|
271
336
|
{
|
|
272
|
-
"Effect": "Allow",
|
|
273
337
|
"Action": "lambda:GetLayerVersion",
|
|
338
|
+
"Effect": "Allow",
|
|
274
339
|
"Resource": "arn:aws:lambda:*:*:layer:*:*"
|
|
275
340
|
}
|
|
276
|
-
]
|
|
341
|
+
],
|
|
342
|
+
"Version": "2012-10-17"
|
|
277
343
|
}
|
|
278
344
|
```
|
|
279
345
|
|
|
@@ -325,11 +391,11 @@ Only [custom authorizers](https://aws.amazon.com/blogs/compute/introducing-custo
|
|
|
325
391
|
|
|
326
392
|
The Custom authorizer is passed an `event` object as below:
|
|
327
393
|
|
|
328
|
-
```
|
|
394
|
+
```js
|
|
329
395
|
{
|
|
330
|
-
"type": "TOKEN",
|
|
331
396
|
"authorizationToken": "<Incoming bearer token>",
|
|
332
|
-
"methodArn": "arn:aws:execute-api:<Region id>:<Account id>:<API id>/<Stage>/<Method>/<Resource path>"
|
|
397
|
+
"methodArn": "arn:aws:execute-api:<Region id>:<Account id>:<API id>/<Stage>/<Method>/<Resource path>",
|
|
398
|
+
"type": "TOKEN"
|
|
333
399
|
}
|
|
334
400
|
```
|
|
335
401
|
|
|
@@ -337,11 +403,11 @@ The `methodArn` does not include the Account id or API id.
|
|
|
337
403
|
|
|
338
404
|
The plugin only supports retrieving Tokens from headers. You can configure the header as below:
|
|
339
405
|
|
|
340
|
-
```
|
|
406
|
+
```js
|
|
341
407
|
"authorizer": {
|
|
342
|
-
"
|
|
408
|
+
"authorizerResultTtlInSeconds": "0",
|
|
343
409
|
"identitySource": "method.request.header.Authorization", // or method.request.header.SomeOtherHeader
|
|
344
|
-
"
|
|
410
|
+
"type": "TOKEN"
|
|
345
411
|
}
|
|
346
412
|
```
|
|
347
413
|
|
|
@@ -369,14 +435,14 @@ If your authentication needs are custom and not satisfied by the existing capabi
|
|
|
369
435
|
```js
|
|
370
436
|
module.exports = function (endpoint, functionKey, method, path) {
|
|
371
437
|
return {
|
|
372
|
-
name: 'your strategy name',
|
|
373
|
-
scheme: 'your scheme name',
|
|
374
|
-
|
|
375
438
|
getAuthenticateFunction: () => ({
|
|
376
439
|
async authenticate(request, h) {
|
|
377
440
|
// your implementation
|
|
378
441
|
},
|
|
379
442
|
}),
|
|
443
|
+
|
|
444
|
+
name: 'your strategy name',
|
|
445
|
+
scheme: 'your scheme name',
|
|
380
446
|
}
|
|
381
447
|
}
|
|
382
448
|
```
|
|
@@ -440,7 +506,7 @@ Now let's make a request with this body: `{ "id": 1 }`
|
|
|
440
506
|
|
|
441
507
|
AWS parses the event as such:
|
|
442
508
|
|
|
443
|
-
```
|
|
509
|
+
```js
|
|
444
510
|
{
|
|
445
511
|
"payload": {
|
|
446
512
|
"id": 1
|
|
@@ -452,7 +518,7 @@ AWS parses the event as such:
|
|
|
452
518
|
|
|
453
519
|
Whereas Offline parses:
|
|
454
520
|
|
|
455
|
-
```
|
|
521
|
+
```js
|
|
456
522
|
{
|
|
457
523
|
"payload": {
|
|
458
524
|
"id": 1
|
|
@@ -504,7 +570,7 @@ Works out of the box. See examples in the manual_test directory.
|
|
|
504
570
|
|
|
505
571
|
Example of enabling proxy:
|
|
506
572
|
|
|
507
|
-
```
|
|
573
|
+
```yml
|
|
508
574
|
custom:
|
|
509
575
|
serverless-offline:
|
|
510
576
|
resourceRoutes: true
|
|
@@ -512,18 +578,18 @@ custom:
|
|
|
512
578
|
|
|
513
579
|
or
|
|
514
580
|
|
|
515
|
-
```
|
|
581
|
+
```yml
|
|
516
582
|
YourCloudFormationMethodId:
|
|
517
|
-
Type: AWS::ApiGateway::Method
|
|
518
583
|
Properties:
|
|
519
584
|
......
|
|
520
585
|
Integration:
|
|
521
586
|
Type: HTTP_PROXY
|
|
522
587
|
Uri: 'https://s3-${self:custom.region}.amazonaws.com/${self:custom.yourBucketName}/{proxy}'
|
|
523
588
|
......
|
|
589
|
+
Type: AWS::ApiGateway::Method
|
|
524
590
|
```
|
|
525
591
|
|
|
526
|
-
```
|
|
592
|
+
```yml
|
|
527
593
|
custom:
|
|
528
594
|
serverless-offline:
|
|
529
595
|
resourceRoutes:
|
|
@@ -541,7 +607,7 @@ May not work properly. Please PR. (Difficulty: hard?)
|
|
|
541
607
|
|
|
542
608
|
Example response velocity template:
|
|
543
609
|
|
|
544
|
-
```
|
|
610
|
+
```js
|
|
545
611
|
"responseParameters": {
|
|
546
612
|
"method.response.header.X-Powered-By": "Serverless", // a string
|
|
547
613
|
"method.response.header.Warning": "integration.response.body", // the whole response
|
|
@@ -558,7 +624,9 @@ Usage in order to send messages back to clients:
|
|
|
558
624
|
Or,
|
|
559
625
|
|
|
560
626
|
```js
|
|
561
|
-
const
|
|
627
|
+
const { ApiGatewayManagementApi } = require('aws-sdk')
|
|
628
|
+
|
|
629
|
+
const apiGatewayManagementApi = new ApiGatewayManagementApi({
|
|
562
630
|
apiVersion: '2018-11-29',
|
|
563
631
|
endpoint: 'http://localhost:3001',
|
|
564
632
|
});
|
|
@@ -603,13 +671,13 @@ Add a new [launch configuration](https://code.visualstudio.com/docs/editor/debug
|
|
|
603
671
|
|
|
604
672
|
```json
|
|
605
673
|
{
|
|
606
|
-
"type": "node",
|
|
607
|
-
"request": "launch",
|
|
608
|
-
"name": "Debug Serverless Offline",
|
|
609
674
|
"cwd": "${workspaceFolder}",
|
|
610
|
-
"
|
|
675
|
+
"name": "Debug Serverless Offline",
|
|
676
|
+
"request": "launch",
|
|
611
677
|
"runtimeArgs": ["run", "debug"],
|
|
612
|
-
"
|
|
678
|
+
"runtimeExecutable": "npm",
|
|
679
|
+
"sourceMaps": true,
|
|
680
|
+
"type": "node"
|
|
613
681
|
}
|
|
614
682
|
```
|
|
615
683
|
|
|
@@ -647,7 +715,7 @@ You can change this profile directly in the code or by setting proper environmen
|
|
|
647
715
|
## Simulation quality
|
|
648
716
|
|
|
649
717
|
This plugin simulates API Gateway for many practical purposes, good enough for development - but is not a perfect simulator.
|
|
650
|
-
Specifically, Lambda currently runs on Node.js
|
|
718
|
+
Specifically, Lambda currently runs on Node.js v12.x, v14.x and v16.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.
|
|
651
719
|
|
|
652
720
|
## Usage with other plugins
|
|
653
721
|
|
|
@@ -660,7 +728,7 @@ Plugins are executed in order, so plugins that process your code or add resource
|
|
|
660
728
|
|
|
661
729
|
For example:
|
|
662
730
|
|
|
663
|
-
```
|
|
731
|
+
```yml
|
|
664
732
|
plugins:
|
|
665
733
|
- serverless-middleware # modifies some of your handler based on configuration
|
|
666
734
|
- serverless-webpack # package your javascript handlers using webpack
|
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.1.1",
|
|
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"
|
|
@@ -162,21 +163,8 @@
|
|
|
162
163
|
"Fernando Alvarez (https://github.com/jefer590)",
|
|
163
164
|
"Eric Carter (https://github.com/ericctsf)"
|
|
164
165
|
],
|
|
165
|
-
"husky": {
|
|
166
|
-
"hooks": {
|
|
167
|
-
"pre-commit": "lint-staged"
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
"lint-staged": {
|
|
171
|
-
"*.js": [
|
|
172
|
-
"eslint"
|
|
173
|
-
],
|
|
174
|
-
"*.{css,html,js,json,md,yaml,yml}": [
|
|
175
|
-
"prettier -c"
|
|
176
|
-
]
|
|
177
|
-
},
|
|
178
166
|
"engines": {
|
|
179
|
-
"node": ">=
|
|
167
|
+
"node": ">=14.18.0"
|
|
180
168
|
},
|
|
181
169
|
"standard-version": {
|
|
182
170
|
"skip": {
|
|
@@ -203,58 +191,46 @@
|
|
|
203
191
|
]
|
|
204
192
|
},
|
|
205
193
|
"dependencies": {
|
|
206
|
-
"@hapi/boom": "^
|
|
194
|
+
"@hapi/boom": "^10.0.0",
|
|
207
195
|
"@hapi/h2o2": "^9.1.0",
|
|
208
196
|
"@hapi/hapi": "^20.2.2",
|
|
209
|
-
"aws-sdk": "^2.
|
|
210
|
-
"boxen": "^
|
|
211
|
-
"chalk": "^
|
|
212
|
-
"
|
|
213
|
-
"execa": "^5.1.1",
|
|
197
|
+
"aws-sdk": "^2.1184.0",
|
|
198
|
+
"boxen": "^7.0.0",
|
|
199
|
+
"chalk": "^5.0.1",
|
|
200
|
+
"execa": "^6.1.0",
|
|
214
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.
|
|
207
|
+
"jszip": "^3.10.0",
|
|
208
|
+
"luxon": "^3.0.1",
|
|
209
|
+
"node-fetch": "^3.2.9",
|
|
223
210
|
"node-schedule": "^2.1.0",
|
|
224
|
-
"
|
|
225
|
-
"p-
|
|
226
|
-
"p-retry": "^
|
|
227
|
-
"semver": "^7.3.7",
|
|
211
|
+
"object.hasown": "^1.1.1",
|
|
212
|
+
"p-memoize": "^7.1.0",
|
|
213
|
+
"p-retry": "^5.1.1",
|
|
228
214
|
"velocityjs": "^2.0.6",
|
|
229
|
-
"ws": "^
|
|
215
|
+
"ws": "^8.8.1"
|
|
230
216
|
},
|
|
231
217
|
"devDependencies": {
|
|
232
|
-
"@babel/cli": "^7.17.10",
|
|
233
|
-
"@babel/core": "^7.17.12",
|
|
234
|
-
"@babel/plugin-proposal-class-properties": "^7.17.12",
|
|
235
|
-
"@babel/plugin-proposal-dynamic-import": "^7.16.7",
|
|
236
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.17.12",
|
|
237
|
-
"@babel/plugin-proposal-optional-chaining": "^7.17.12",
|
|
238
|
-
"@babel/plugin-transform-modules-commonjs": "^7.17.12",
|
|
239
|
-
"@babel/register": "^7.17.7",
|
|
240
218
|
"archiver": "^5.3.1",
|
|
241
|
-
"
|
|
242
|
-
"eslint": "^8.15.0",
|
|
219
|
+
"eslint": "^8.20.0",
|
|
243
220
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
244
221
|
"eslint-config-prettier": "^8.5.0",
|
|
245
222
|
"eslint-plugin-import": "^2.25.4",
|
|
246
|
-
"eslint-plugin-prettier": "^4.
|
|
223
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
247
224
|
"git-list-updated": "^1.2.1",
|
|
248
|
-
"husky": "^
|
|
249
|
-
"
|
|
250
|
-
"
|
|
251
|
-
"
|
|
252
|
-
"
|
|
253
|
-
"rimraf": "^3.0.2",
|
|
254
|
-
"serverless": "^2.72.3",
|
|
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",
|
|
255
230
|
"standard-version": "^9.5.0"
|
|
256
231
|
},
|
|
257
232
|
"peerDependencies": {
|
|
258
|
-
"serverless": "^
|
|
233
|
+
"@serverless/utils": "^6.7.0",
|
|
234
|
+
"serverless": "^3.2.0"
|
|
259
235
|
}
|
|
260
236
|
}
|