lambdaruntime

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 14 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 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

This section is empty.

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.

func NewPool

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

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

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) Size

func (p *Pool) Size() int

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

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