handler

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 18 Imported by: 4

README

AWS Lambda Handler

Provides a wrapper method (with logging and XRay tracing) to start a lambda function.

Usage:

import "github.com/ockendenjo/handler"

func main() {
    handler.BuildAndStart(func(awsConfig aws.Config) handler.Handler[events.APIGatewayProxyRequest, events.APIGatewayProxyResponse] {
        //Set up any AWS SDK clients here (using awsConfig)
        
        return func(ctx context.Context, event events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
            //This function is invoked for every lambda invocation
            response := events.APIGatewayProxyResponse{
                StatusCode: 200,
            }
            return response, nil
        }
    })
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildAndStart

func BuildAndStart[T interface{}, U interface{}](getHandler func(awsConfig aws.Config) Handler[T, U])

BuildAndStart configures a logger, instruments the handler with OpenTelemetry, instruments the AWS SDK, and then starts the lambda

func BuildAndStartCustomResource

func BuildAndStartCustomResource(getHandler func(awsConfig aws.Config) cfn.CustomResourceFunction)

func ContextWithLogger

func ContextWithLogger(ctx context.Context) context.Context

func GetLogger

func GetLogger(ctx context.Context) *slog.Logger

func GetNewContextWithLogger

func GetNewContextWithLogger(parent context.Context, logger *slog.Logger) context.Context

func MustGetEnv

func MustGetEnv(key string) string

func MustGetEnvInt

func MustGetEnvInt(key string) int

func SQSAllFail

func SQSAllFail(event events.SQSEvent) events.SQSEventResponse

Types

type Handler

type Handler[T interface{}, U interface{}] func(ctx context.Context, event T) (U, error)

func GetSQSHandler

func GetSQSHandler(processRecord SQSRecordProcessor) Handler[events.SQSEvent, events.SQSEventResponse]

GetSQSHandler returns a lambda handler that will process each SQS message in parallel using the provided processRecord function

func WithLogger

func WithLogger[T interface{}, U interface{}](handlerFunc Handler[T, U]) Handler[T, U]

type SQSRecordProcessor

type SQSRecordProcessor func(ctx context.Context, record events.SQSMessage) error

Jump to

Keyboard shortcuts

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