Skip to content

Commit 5e0fa29

Browse files
authored
add initial docs for Lambda stay open mode (#84)
1 parent 89e93e1 commit 5e0fa29

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

.hugo_build.lock

Whitespace-only changes.

content/en/localstack/configuration.md

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ This section covers configuration values that are specific to AWS services.
9999
| | `docker` (default) | Run each function invocation in a separate Docker container. |
100100
| | `local` (fallback) | Run Lambda functions in a temporary directory on the local machine. |
101101
| | `docker-reuse` | Create one Docker container per function and reuse it across invocations. |
102+
| `LAMBDA_STAY_OPEN_MODE` | `1` (default) | Usage of the [stay-open mode]({{< ref "lambda-executors#stay-open-mode" >}}) of Lambda containers. Only applicable if `LAMBDA_EXECUTOR=docker-reuse`. |
102103
| `LAMBDA_REMOTE_DOCKER` | | determines whether Lambda code is copied or mounted into containers |
103104
| | `true` (default) | your Lambda function definitions will be passed to the container by copying the zip file (potentially slower). It allows for remote execution, where the host and the client are not on the same machine.|
104105
| | `false` | your Lambda function definitions will be passed to the container by mounting a volume (potentially faster). This requires to have the Docker client and the Docker host on the same machine. Also, `HOST_TMP_FOLDER` must be set properly, and a volume mount like `${HOST_TMP_FOLDER}:/tmp/localstack` needs to be configured if you're using docker-compose. |

content/en/localstack/lambda-executors.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,29 @@ A typical invocation of a dummy python lambda can take around 3 seconds from sta
4545
All supported lambda types can be used with this executor.
4646

4747

48-
### Docker re-use
48+
### Docker reuse
4949

5050
Configuration: `LAMBDA_EXECUTOR=docker-reuse`
5151

52+
#### Stay-open mode
53+
LocalStack allows to use the stay-open mode of its lambda containers.
54+
The containers stay open and wait for further invocations, without executing the initialization code of the lambda multiple times.
55+
This results in way faster execution times, especially if the lambda has long-running initialization code.
56+
57+
The stay-open mode is the new default method when using `docker-reuse` as lambda executor, however, it has some restrictions:
58+
59+
* Only works if LocalStack runs in a Docker container
60+
* Large Payloads (multiple MBs) do not work
61+
* Problems with error handling in some runtimes
62+
63+
A list of failing tests with this mode can be found [in this GitHub issue](https://github.com/localstack/localstack/pull/5088).
64+
65+
66+
#### Docker-exec execution mode
67+
This mode is the default if LocalStack is started in host mode.
68+
If you experience failures using the stay-open mode (either due to the mentioned restrictions or networking problems), you can force this mode by setting `LAMBDA_STAY_OPEN_MODE=0`.
69+
5270
This execution mode provides a balance between the speed of a local execution and the feature set and isolation of the `docker` executor.
5371
While the initial call, which creates the container, will take roughly the same time of `docker` executor, the subsequent invocations will only take around 1 second (start to finish, invoked using the awscli), which roughly the time an actual aws invocation using this method takes.
5472
The container is kept running 10 minutes after the last invocation for this lambda, then it will be destroyed (and recreated if necessary for the next invocation).
73+
The complete lambda process is called using `docker-exec` each time of the invocation. While the invocation is still faster than `docker` execution mode, it is not as fast as with the stay-open mode (since the lambda has to be loaded and initialized every time).

0 commit comments

Comments
 (0)