Skip to content

Lambda runtime ​

Functions run in containers and talk to Gopherstack over the Lambda Runtime API. Both Zip and Image package types are supported. Zip functions are mounted into an AWS runtime base image. Zip code comes from Code.ZipFile or Code.S3Bucket plus Code.S3Key.

A container runtime is required: Docker, Podman, or Kubernetes (see the Kubernetes Pod executor in the Kubernetes guide).

Invocation flow ​

  1. Gopherstack pulls the image if it is not cached, and starts a container with AWS_LAMBDA_RUNTIME_API=<LAMBDA_DOCKER_HOST>:<port>.
  2. The runtime polls GET /2018-06-01/runtime/invocation/next.
  3. Gopherstack sends the payload. The runtime posts the result to /2018-06-01/runtime/invocation/<id>/response (or /error).
  4. The container returns to a warm pool and is reused.

The Runtime API listens on a port allocated from PORT_RANGE_START-PORT_RANGE_END. The container must be able to reach LAMBDA_DOCKER_HOST (on Linux with the default Docker bridge, 172.17.0.1).

Supported endpoints: /2018-06-01/runtime/invocation/next, /2018-06-01/runtime/invocation/<id>/response, /2018-06-01/runtime/invocation/<id>/error, /2018-06-01/runtime/init/error, plus the Extensions API (register, event/next, init/error, exit/error) and the Telemetry and Logs subscription APIs.

Warm pool ​

Each function keeps up to --lambda-pool-size warm containers. Containers idle longer than --lambda-idle-timeout are stopped and removed.

Settings ​

FlagEnv varDefaultDescription
--lambda-docker-hostLAMBDA_DOCKER_HOST172.17.0.1Host containers use to reach Gopherstack
--lambda-container-runtimeCONTAINER_RUNTIMEdockerdocker, podman, auto or kubernetes
--lambda-isolationLAMBDA_ISOLATIONcontainercontainer, gvisor, kata (firecracker is not supported)
--lambda-pool-sizeLAMBDA_POOL_SIZE3Warm containers per function
--lambda-idle-timeoutLAMBDA_IDLE_TIMEOUT10mIdle container lifetime
--lambda-max-runtimesLAMBDA_MAX_RUNTIMES50Maximum simultaneous runtimes
--lambda-keep-containersLAMBDA_KEEP_CONTAINERSfalseKeep containers after the function stops
--lambda-docker-flagsLAMBDA_DOCKER_FLAGSemptyExtra docker options for function containers
--lambda-strict-runtime-validationLAMBDA_STRICT_RUNTIME_VALIDATIONfalseReject deprecated runtimes
--lambda-disable-hot-reloadLAMBDA_DISABLE_HOT_RELOADfalseDisable hot reload from local directories
--lambda-hot-reload-interval-msLAMBDA_HOT_RELOAD_INTERVAL_MS250Minimum time between hot-reload change scans

Account limits, all default 0 (unset): --lambda-account-concurrent-executions, --lambda-account-min-unreserved-concurrency, --lambda-account-total-code-size, --lambda-code-size-zipped, --lambda-code-size-unzipped, --lambda-create-function-request-size, --lambda-max-environment-bytes.

CONTAINER_HOST overrides the Podman socket path.

Invoking ​

bash
# synchronous
aws --endpoint-url http://localhost:8000 lambda invoke \
    --function-name my-function --payload '{"key":"value"}' response.json

# asynchronous: returns 202 immediately
aws --endpoint-url http://localhost:8000 lambda invoke \
    --function-name my-function --invocation-type Event --payload '{"key":"value"}' /dev/null

Event source mappings ​

SQS, Kinesis, DynamoDB Streams and Kafka sources are supported. Gopherstack polls the source and delivers batches.

bash
aws --endpoint-url http://localhost:8000 lambda create-event-source-mapping \
    --function-name my-function \
    --event-source-arn arn:aws:sqs:us-east-1:000000000000:my-queue \
    --batch-size 10

Function URLs ​

bash
aws --endpoint-url http://localhost:8000 lambda create-function-url-config \
    --function-name my-function --auth-type NONE

The URL host is AWS-shaped: <url-id>.lambda-url.<region>.on.aws. Each URL gets a port from the allocator range. With embedded DNS the name resolves to Gopherstack.

Hot reload ​

A function created with Code.S3Bucket=hot-reload and Code.S3Key set to a host directory runs that directory and reloads it when files change. Some host paths (/proc, /etc, /root, Docker and Podman state directories, ...) are refused.

Podman ​

bash
systemctl --user enable --now podman.socket
export CONTAINER_RUNTIME=podman
export CONTAINER_HOST=unix://${XDG_RUNTIME_DIR}/podman/podman.sock   # optional
export LAMBDA_DOCKER_HOST=host.containers.internal                   # rootless networking
gopherstack

Troubleshooting ​

ProblemFix
Container cannot reach GopherstackSet LAMBDA_DOCKER_HOST to the Docker bridge IP (ip addr show docker0)
Image pull failsCheck that docker pull <image> works from your shell (registry credentials and mirrors are in the Docker guide)
Cold starts are slowRaise --lambda-pool-size

Released under the MIT License.