Help us shape the future of Go! Take the 2026 Go Developer Survey

lambda

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 40 Imported by: 0

Documentation

Overview

Package lambda emulates AWS Lambda (REST-JSON): functions, versions, aliases, layers, permissions, function URLs and event source mappings. Python and Node.js handlers run as warm local processes behind an embedded Runtime API client; other runtimes and container images run in Docker.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTTPEvent

func HTTPEvent(r *http.Request, apiID, routeKey string) []byte

HTTPEvent builds an API Gateway HTTP API / function URL payload (version 2.0).

func SDKDir

func SDKDir(dataDir string) string

SDKDir holds the AWS SDKs native runtimes lack (see `pogi lambda-sdks`): node_modules for Node.js, python/ for boto3. Function code is unpacked below it, so Node's module lookup finds the SDK without NODE_PATH.

func WriteHTTPResult

func WriteHTTPResult(w http.ResponseWriter, result []byte)

WriteHTTPResult maps a function result to an HTTP response (payload 2.0 rules): an object with statusCode is a full response, anything else is a JSON body.

Types

type Alias

type Alias struct {
	Name        string             `json:"name"`
	Version     string             `json:"version"`
	Description string             `json:"description,omitempty"`
	Weights     map[string]float64 `json:"weights,omitempty"`
	RevisionID  string             `json:"revisionId"`
}

Alias points at a version, optionally splitting traffic.

type Config

type Config struct {
	Version       string            `json:"version"`
	Runtime       string            `json:"runtime,omitempty"`
	Handler       string            `json:"handler,omitempty"`
	Role          string            `json:"role"`
	Description   string            `json:"description,omitempty"`
	Timeout       int               `json:"timeout"`
	MemorySize    int               `json:"memorySize"`
	Env           map[string]string `json:"env,omitempty"`
	PackageType   string            `json:"packageType"`
	ImageURI      string            `json:"imageUri,omitempty"`
	ImageConfig   *ImageConfig      `json:"imageConfig,omitempty"`
	Code          []byte            `json:"code,omitempty"`
	CodeDir       string            `json:"codeDir,omitempty"` // hot reload
	CodeSha256    string            `json:"codeSha256"`
	CodeSize      int64             `json:"codeSize"`
	Layers        []string          `json:"layers,omitempty"`
	Architectures []string          `json:"architectures,omitempty"`
	DeadLetterArn string            `json:"deadLetterArn,omitempty"`
	TracingMode   string            `json:"tracingMode,omitempty"`
	Ephemeral     int               `json:"ephemeral,omitempty"`
	Vpc           json.RawMessage   `json:"vpc,omitempty"`
	Modified      time.Time         `json:"modified"`
	RevisionID    string            `json:"revisionId"`
}

Config is one immutable (or $LATEST) function configuration.

type Function

type Function struct {
	Name        string                  `json:"name"`
	Account     string                  `json:"account"`
	Region      string                  `json:"region"`
	Latest      *Config                 `json:"latest"`
	Versions    map[string]*Config      `json:"versions,omitempty"`
	NextVersion int                     `json:"nextVersion"`
	Aliases     map[string]*Alias       `json:"aliases,omitempty"`
	Policy      []map[string]any        `json:"policy,omitempty"`
	Tags        map[string]string       `json:"tags,omitempty"`
	Reserved    *int                    `json:"reserved,omitempty"`
	Provisioned map[string]*Provisioned `json:"provisioned,omitempty"` // version or alias → provisioned concurrency
	URL         *URLConfig              `json:"url,omitempty"`
	EventInvoke map[string]any          `json:"eventInvoke,omitempty"`
}

Function is a function with its $LATEST config, versions and aliases.

type ImageConfig

type ImageConfig struct {
	EntryPoint       []string `json:",omitempty"`
	Command          []string `json:",omitempty"`
	WorkingDirectory string   `json:",omitempty"`
}

ImageConfig overrides a container image's entrypoint, command and working directory.

type InvokeResult

type InvokeResult struct {
	Payload string
	Error   string
	Logs    string
	Elapsed time.Duration
}

InvokeResult is what the console shows after a test invoke.

type Layer

type Layer struct {
	Name     string                `json:"name"`
	Account  string                `json:"account"`
	Region   string                `json:"region"`
	Versions map[int]*LayerVersion `json:"versions"`
	Next     int                   `json:"next"`
}

Layer holds the versions of one layer.

type LayerVersion

type LayerVersion struct {
	Version     int       `json:"version"`
	Zip         []byte    `json:"zip"`
	Sha         string    `json:"sha"`
	Description string    `json:"description,omitempty"`
	License     string    `json:"license,omitempty"`
	Runtimes    []string  `json:"runtimes,omitempty"`
	Archs       []string  `json:"archs,omitempty"`
	Created     time.Time `json:"created"`
}

LayerVersion is one published layer version.

type Mapping

type Mapping struct {
	UUID              string            `json:"uuid"`
	Account           string            `json:"account"`
	Region            string            `json:"region"`
	FunctionArn       string            `json:"functionArn"`
	SourceArn         string            `json:"sourceArn"`
	BatchSize         int               `json:"batchSize"`
	Window            int               `json:"window"`
	StartingPosition  string            `json:"startingPosition,omitempty"`
	StartingTimestamp float64           `json:"startingTimestamp,omitempty"`
	Enabled           bool              `json:"enabled"`
	Filters           []string          `json:"filters,omitempty"`
	ResponseTypes     []string          `json:"responseTypes,omitempty"`
	MaxRetry          int               `json:"maxRetry"`
	Bisect            bool              `json:"bisect,omitempty"`
	MaxConcurrency    int               `json:"maxConcurrency,omitempty"` // ScalingConfig.MaximumConcurrency, kept but not used to limit polling
	OnFailure         string            `json:"onFailure,omitempty"`
	Topics            []string          `json:"topics,omitempty"`        // self-managed Kafka
	Endpoints         []string          `json:"endpoints,omitempty"`     // its KAFKA_BOOTSTRAP_SERVERS
	Access            []accessConfig    `json:"access,omitempty"`        // its SourceAccessConfigurations
	ConsumerGroup     string            `json:"consumerGroup,omitempty"` // its consumer group id
	Modified          time.Time         `json:"modified"`
	LastResult        string            `json:"lastResult"`
	Tags              map[string]string `json:"tags,omitempty"`
}

Mapping is an event source mapping (SQS, DynamoDB Streams, Kinesis or self-managed Kafka → function).

type Provisioned

type Provisioned struct {
	Requested int       `json:"requested"`
	Status    string    `json:"status"` // IN_PROGRESS, READY or FAILED
	Reason    string    `json:"reason,omitempty"`
	Modified  time.Time `json:"modified"`
}

Provisioned is the provisioned concurrency of a version or alias.

type Service

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

Service is the Lambda emulator.

func New

func New(hub *core.Hub) *Service

New creates the Lambda service.

func (*Service) BodyLimit

func (s *Service) BodyLimit(r *http.Request) int64

BodyLimit raises the upload limit for function code: CreateFunction, UpdateFunctionCode and PublishLayerVersion carry a zip of up to 50 MB as base64 in JSON.

func (*Service) Close

func (s *Service) Close() error

Close stops every runtime process and poller.

func (*Service) Info

func (s *Service) Info() core.Info

func (*Service) Inspect

func (s *Service) Inspect(table, id string) any

Inspect returns a function's configuration, versions, aliases, policy and recent logs.

func (*Service) Invoke

func (s *Service) Invoke(account, region, name string, payload []byte) (InvokeResult, error)

Invoke runs a function synchronously from the console.

func (s *Service) Links() []core.Link

Links are the event source mappings, from the stream or queue to the function.

func (*Service) Load

func (s *Service) Load(b []byte) error

func (*Service) RecentLogs

func (s *Service) RecentLogs(account, region, name string) []string

RecentLogs returns the last log lines of a function.

func (*Service) Reset

func (s *Service) Reset()

func (*Service) Resources

func (s *Service) Resources() []core.Table

Resources lists functions and event source mappings.

func (*Service) Save

func (s *Service) Save() ([]byte, error)

func (*Service) ServeHTTP

func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Service) TaggedResources

func (s *Service) TaggedResources(account, region string) map[string]map[string]string

TaggedResources lists functions (ARN → tags) for the tagging API and Resource Explorer.

func (*Service) Tick

func (s *Service) Tick(now time.Time)

Tick keeps provisioned environments started, then stops idle environments unused for keepAlive. New runs it every 5 seconds; tests call it with any time.

type URLConfig

type URLConfig struct {
	ID       string          `json:"id"`
	AuthType string          `json:"authType"`
	Cors     json.RawMessage `json:"cors,omitempty"`
	Mode     string          `json:"mode,omitempty"`
	Created  time.Time       `json:"created"`
}

URLConfig is a function URL.

Jump to

Keyboard shortcuts

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