partialbatch

package module
v0.0.0-...-0a1fb86 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: MIT Imports: 3 Imported by: 0

README

lambda-partialbatch Go Reference

Support for AWS Lambda's Partial Batch Response for DynamoDB, Kinesis and SQS in Golang

Example

package main

import (
	"context"
	"log"

	"github.com/aws/aws-lambda-go/events"
	"github.com/aws/aws-lambda-go/lambda"
	partialbatch "github.com/bored-engineer/lambda-partialbatch"
)

func handler(ctx context.Context, msg events.SQSMessage) error {
	// TODO: Some processing that could fail
	return nil
}

func main() {
	// Process batches of SQS messages
	lambda.Start(partialbatch.SQS(
		handler,
		// Recover from any panics, treating as a failed record
		partialbatch.WithRecovery(true),
		// For FIFO queues, halt after the first failure
		partialbatch.WithHalt(true),
		// Log any errors for debugging/alerting
		partialbatch.WithErrorCallback(func(_ context.Context, itemIdentifier string, err error) {
			log.Printf("failed to process SQS message %q: %s", itemIdentifier, err)
		}),
	))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DynamoDBHandler

DynamoDBHandler processes a single events.DynamoDBEventRecord

type DynamoDBProcessor

DynamoDBProcessor can be passed directly to lamdba.Handle

func DynamoDB

func DynamoDB[THandler DynamoDBHandler](handler THandler, opts ...Option) DynamoDBProcessor

DynamoDB processes each DynamoDBEventRecord in a DynamoDBEvent by invoking the provided DynamoDBHandler

type ErrorFunc

type ErrorFunc func(ctx context.Context, itemIdentifier string, err error)

type KinesisEventHandler

KinesisEventHandler processes a single events.KinesisEventRecord

type KinesisProcessor

DynamoDBProcessor can be passed directly to lamdba.Handle

func Kinesis

func Kinesis[THandler KinesisEventHandler](handler THandler, opts ...Option) KinesisProcessor

Kinesis processes each DynamoDBEventRecord in a DynamoDBEvent by invoking the provided DynamoDBHandler

type Option

type Option func(*options)

Option modifies the behavior of the event processing

func WithErrorCallback

func WithErrorCallback(cb ErrorFunc) Option

WithErrorCallback is invoked (if non-nil) when an error occurs processing an item Typically this is used to log the error for debugging/alerting

func WithHalt

func WithHalt(v bool) Option

WithHalt changes the behavior to halt when an error occurs instead of continuing

func WithRecovery

func WithRecovery(v bool) Option

WithRecovery captures any panics treating them as a returned error

type SQSHandler

type SQSHandler interface {
	func(context.Context, events.SQSMessage) error |
		func(context.Context, events.SQSMessage) |
		func(events.SQSMessage) error |
		func(events.SQSMessage)
}

SQSHandler processes a single events.SQSMessage

type SQSProcessor

SQSProcessor can be passed directly to lamdba.Handle

func SQS

func SQS[THandler SQSHandler](handler THandler, opts ...Option) SQSProcessor

SQS processes each SQSMessage in a SQSEvent by invoking the provided SQSHandler

Jump to

Keyboard shortcuts

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