wloglambda

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

This file holds the batch helpers: one message event per record, and the failure list that tells the event source which records to retry.

Package wloglambda is wlog's AWS Lambda adapter: one function event per invocation, one message event per batch record, and a flush before the runtime freezes the process.

A Lambda container stays warm, so the drains stay open and every invocation flushes. The event source mapping of a batch function must set ReportBatchItemFailures, or AWS ignores the returned failure list and retries the whole batch.

Read top to bottom: Wrap gives every invocation one event, ProcessSQS, ProcessKinesis, and ProcessDynamoDB give every record of a batch its own event, and SIGTERMFlush flushes the drains on the spindown signal. The setup line lives in docs/async-adapters.md, which `make snippets` compiles.

This file holds the spindown flush.

This file holds the invocation wrapper, the cold start flag, the known event types, and the trace of one invocation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProcessDynamoDB

ProcessDynamoDB gives every record of one DynamoDB stream batch its own message event, and returns the ids of the records whose handler failed. It never reads the item images, because an item holds user data. A nil Logger means wlog.Default.

func ProcessKinesis

ProcessKinesis gives every record of one Kinesis batch its own message event, and returns the ids of the records whose handler failed. A nil Logger means wlog.Default.

func ProcessSQS

ProcessSQS gives every record of one SQS batch its own message event, and returns the ids of the records whose handler failed, so the event source retries only those records. The event source mapping must set ReportBatchItemFailures, or AWS ignores the list and retries the whole batch. A nil Logger means wlog.Default.

func SIGTERMFlush

func SIGTERMFlush(log *wlog.Logger) lambda.Option

SIGTERMFlush returns a lambda.Option that flushes the drains when the runtime sends SIGTERM, which is the last moment before the runtime kills the process. Pass it to lambda.Start next to the other options.

func Wrap

func Wrap[TIn, TOut any](log *wlog.Logger, h func(context.Context, TIn) (TOut, error), opts ...Option) func(context.Context, TIn) (TOut, error)

Wrap returns a handler that gives every invocation one function event. It records the invocation id, the function name and version, the cold start flag, and the remaining time, and it fills the http group and the status for API Gateway v1, API Gateway v2, and ALB events. It flushes the drains before it returns, and it flushes before a panic continues, because a Lambda freezes the process between invocations. A nil Logger means wlog.Default.

Types

type Option

type Option func(*config)

Option configures Wrap.

func WithFlushTimeout

func WithFlushTimeout(d time.Duration) Option

WithFlushTimeout sets the budget of the flush that runs after every invocation, and after a panic. A Lambda with a short timeout needs a smaller budget than the default of 2 seconds.

Jump to

Keyboard shortcuts

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