lambdaruntime

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package lambdaruntime runs Lambda functions as supervised local processes that speak the AWS Lambda Runtime API. Each function gets one child process (serial invocations in this phase) started with AWS_LAMBDA_RUNTIME_API pointing at a per-function loopback listener serving the four runtime routes:

GET  /2018-06-01/runtime/invocation/next
POST /2018-06-01/runtime/invocation/{id}/response
POST /2018-06-01/runtime/invocation/{id}/error
POST /2018-06-01/runtime/init/error

The official runtime interface clients (provided.al2 bootstrap, awslambdaric for Python/Node) speak this protocol unmodified — so real handlers run with no Docker.

Index

Constants

View Source
const DefaultIdleTimeout = 10 * time.Minute

DefaultIdleTimeout is how long a fully-idle pool keeps its warm child processes before reaping them to zero. Long enough that active development keeps warm-start latency, short enough that a walked-away-from stack releases the memory. AWS reaps idle execution environments on a similar horizon.

View Source
const DefaultPoolMax = 5

DefaultPoolMax is the concurrency ceiling for a function with no reserved concurrency configured — how many child processes can run its invocations at once. Kept modest so a local stack doesn't fork a process per request.

Variables

View Source
var ErrPoolClosed = errors.New("lambda pool closed")

ErrPoolClosed is returned by Invoke when the pool has been stopped (e.g. a concurrent restart). Callers may retry against a freshly-created pool.

Functions

This section is empty.

Types

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool runs a function's invocations across a growable set of Runners (one child process each), giving up to Max concurrent executions. It grows lazily to match observed concurrency and never exceeds Max — the local analogue of Lambda's per-function concurrency. Under serial load it stays at one Runner.

When the pool goes fully idle (no invocation in flight) it scales back to zero after idleTimeout: every warm process is stopped and the next invoke spawns a fresh one. So a function you stop calling stops costing memory.

func NewPool

func NewPool(spec Spec, max int, logf func(string, ...any)) *Pool

NewPool builds a pool. max <= 0 uses DefaultPoolMax.

func (*Pool) IdleTimeout added in v0.2.0

func (p *Pool) IdleTimeout() time.Duration

IdleTimeout returns the pool's scale-to-zero window.

func (*Pool) Invoke

func (p *Pool) Invoke(ctx context.Context, payload []byte) (Result, error)

Invoke runs one invocation on a pooled Runner, spawning another (up to Max) when concurrent demand exceeds the current pool size.

func (*Pool) SetIdleTimeout added in v0.2.0

func (p *Pool) SetIdleTimeout(d time.Duration)

SetIdleTimeout overrides how long a fully-idle pool stays warm before it scales to zero. A value <= 0 restores DefaultIdleTimeout. Safe to call before the pool is first used.

func (*Pool) Size

func (p *Pool) Size() int

Size returns the current number of live runners (for tests/introspection).

func (*Pool) SleepDeadline added in v0.2.0

func (p *Pool) SleepDeadline() (time.Time, bool)

SleepDeadline reports when the warm pool will scale to zero and whether a countdown is currently running (true only when warm and idle). It returns the zero time and false when the pool is cold or actively executing.

func (*Pool) Stop

func (p *Pool) Stop()

Stop tears down every child process in the pool.

type Result

type Result struct {
	Payload     []byte
	FunctionErr string // non-empty on a handler error (X-Amz-Function-Error)
	Logs        []byte // tail of stdout/stderr
}

Result is one invocation's outcome.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner supervises one function's process and Runtime API listener.

func NewRunner

func NewRunner(spec Spec, logf func(string, ...any)) *Runner

NewRunner builds a runner (the process starts on first Invoke).

func (*Runner) Invoke

func (r *Runner) Invoke(ctx context.Context, payload []byte) (Result, error)

Invoke runs the function synchronously (serial: one in flight at a time).

func (*Runner) Stop

func (r *Runner) Stop()

Stop terminates the process and listener.

type Spec

type Spec struct {
	Name      string
	Handler   string
	Runtime   string            // provided.*, go, python3.x, nodejs*
	Command   []string          // explicit command (doze extension) — wins over Runtime mapping
	Dir       string            // working directory
	Env       map[string]string // function environment
	Timeout   time.Duration
	Endpoints map[string]string // AWS_ENDPOINT_URL_* injected so handlers reach sibling services
}

Spec describes how to run one function.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL