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 ¶
- func ProcessDynamoDB(ctx context.Context, log *wlog.Logger, e events.DynamoDBEvent, ...) events.DynamoDBEventResponse
- func ProcessKinesis(ctx context.Context, log *wlog.Logger, e events.KinesisEvent, ...) events.KinesisEventResponse
- func ProcessSQS(ctx context.Context, log *wlog.Logger, e events.SQSEvent, ...) events.SQSEventResponse
- func SIGTERMFlush(log *wlog.Logger) lambda.Option
- func Wrap[TIn, TOut any](log *wlog.Logger, h func(context.Context, TIn) (TOut, error), opts ...Option) func(context.Context, TIn) (TOut, error)
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ProcessDynamoDB ¶
func ProcessDynamoDB(ctx context.Context, log *wlog.Logger, e events.DynamoDBEvent, fn func(context.Context, events.DynamoDBEventRecord) error) events.DynamoDBEventResponse
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 ¶
func ProcessKinesis(ctx context.Context, log *wlog.Logger, e events.KinesisEvent, fn func(context.Context, events.KinesisEventRecord) error) events.KinesisEventResponse
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 ¶
func ProcessSQS(ctx context.Context, log *wlog.Logger, e events.SQSEvent, fn func(context.Context, events.SQSMessage) error) events.SQSEventResponse
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 ¶
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 ¶
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.