lambda

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 15 Imported by: 0

README

bootstrap/function/adapter/contrib/aws/aws-lambda-go/v1

Runs a function.Handler[T] as an AWS Lambda function (the lambda command), on aws-lambda-go.

fxfact.NewApp(
	fx.Provide(func() function.Handler[*event.Event] { return handle }),
	lambdafx.Module[*event.Event](),
	functionfx.Module[*event.Event](middlewares),
).Run()

Set boost.bootstrap.function.default to lambda, or run app lambda.

Triggers

Every record of the invocation becomes one CloudEvent:

Trigger CloudEvent
SQS the body, when it is a CloudEvent; an SNS message delivered to SQS is unwrapped first; otherwise the body is the data and the message id the id
SNS the message, when it is a CloudEvent; otherwise the message is the data, the message id the id and the SNS type the type
Kinesis the record data, when it is a CloudEvent; otherwise the data
S3 the S3 entity as data, the object key as id
DynamoDB Streams the stream record as data; the user identity in useridentitytype and useridentityprincipalid
EventBridge (schedules, CloudWatch Events) the detail as data, the detail type as type

A payload that is not JSON becomes text/plain data. When the payload is not a CloudEvent, id, type and source fall back to the record's event id, event name and event source. Every event carries the extensions awsrequestid and invokedfunctionarn.

A trigger it does not know fails the invocation with a not-implemented error.

Errors

The records of one invocation are handled up to maxWorkers at the same time. When any of them fails, the invocation fails, so Lambda delivers the batch again; the others are still handled. An error registered with errors.Ignore(err, errors.IgnoreAsSuccess) does not fail it.

Config

Key Default Meaning
boost.bootstrap.function.adapter.lambda.skip false acknowledges every invocation without calling the handler
boost.bootstrap.function.adapter.lambda.maxWorkers 10 records of one invocation handled at the same time; 1 keeps their order

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New[T any]() function.CmdFunc[T]

New returns the CmdFunc that runs the handler as an AWS Lambda function, with the options read from config.

func NewWithOptions

func NewWithOptions[T any](o *Options) function.CmdFunc[T]

NewWithOptions returns the CmdFunc that runs the handler as an AWS Lambda function with the given options.

Types

type Event

type Event struct {
	ID         string          `json:"id"`
	Source     string          `json:"source"`
	Region     string          `json:"region"`
	DetailType string          `json:"detail-type"`
	Detail     json.RawMessage `json:"detail"`
	Time       time.Time       `json:"time"`
	Account    string          `json:"account"`
	Resources  []string        `json:"resources"`
	Records    []Record        `json:"Records"`
}

Event is the payload of one invocation: the records of an SQS, SNS, Kinesis, S3 or DynamoDB trigger, or an EventBridge (CloudWatch Events) event, which has no records.

type Handler

type Handler[T any] struct {
	// contains filtered or unexported fields
}

Handler turns each record of a Lambda invocation into a CloudEvent and calls the function handler with it.

func NewHandler

func NewHandler[T any](fn function.Handler[T], options *Options) *Handler[T]

NewHandler returns a Handler that calls fn with the given options.

func (*Handler[T]) Handle

func (h *Handler[T]) Handle(ctx context.Context, e Event) error

Handle is the Lambda entry point. Every record is handled, at most MaxWorkers at the same time; when any of them fails the invocation fails, so Lambda delivers the batch again. An error the errors registry ignores as success does not fail it.

type Options

type Options struct {
	// Skip acknowledges every invocation without calling the handler.
	Skip bool
	// MaxWorkers bounds the records of one invocation handled at the same
	// time; 1 handles them in the order Lambda delivered them.
	MaxWorkers int
}

Options configures the Lambda adapter.

func NewOptions

func NewOptions() (*Options, error)

NewOptions returns the options read from config.

type Record

type Record struct {
	EventVersion           string                                `json:"eventVersion"`
	EventSubscriptionArn   string                                `json:"eventSubscriptionArn"`
	EventSource            string                                `json:"eventSource"`
	EventName              string                                `json:"eventName"`
	EventID                string                                `json:"eventID"`
	SNS                    events.SNSEntity                      `json:"sns"`
	S3                     events.S3Entity                       `json:"s3"`
	Kinesis                events.KinesisRecord                  `json:"kinesis"`
	DynamoDB               events.DynamoDBStreamRecord           `json:"dynamodb"`
	MessageId              string                                `json:"messageId"`
	ReceiptHandle          string                                `json:"receiptHandle"`
	Body                   string                                `json:"body"`
	Md5OfBody              string                                `json:"md5OfBody"`
	Md5OfMessageAttributes string                                `json:"md5OfMessageAttributes"`
	Attributes             map[string]string                     `json:"attributes"`
	MessageAttributes      map[string]events.SQSMessageAttribute `json:"messageAttributes"`
	EventSourceARN         string                                `json:"eventSourceARN"`
	AWSRegion              string                                `json:"awsRegion"`
	UserIdentity           *events.DynamoDBUserIdentity          `json:"userIdentity"`
}

Record is one record of a trigger; only the fields of its EventSource are set.

Jump to

Keyboard shortcuts

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