lambdahooks

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2021 License: Apache-2.0 Imports: 6 Imported by: 1

README

lambdahooks-go

Lambda pre and post execution hooks

Documentation

Index

Constants

View Source
const (
	// MaxDeadlineCushion is the timeout limit for deadline cushion.
	// Deadline cushion should not exceed lambda timeout
	// https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html
	// But setting the cushion at this limit effectively signals timeout
	// to post hooks by default
	MaxDeadlineCushion = 15 * time.Minute

	// DefaultTimeout is the default timeout limit
	// https://docs.aws.amazon.com/lambda/latest/dg/configuration-console.html
	DefaultTimeout = 3 * time.Second
)

Variables

This section is empty.

Functions

func AddPostHook

func AddPostHook(hook PostHook)

AddPostHook adds a post hook to be notified after execution

func AddPreHook

func AddPreHook(hook PreHook)

AddPreHook adds a pre hook to be notified before execution

func Init added in v0.1.0

func Init(options ...Option) error

Init sets up the hooks before use Overrides defaults as needed

func RemovePostHook

func RemovePostHook(hook PostHook)

RemovePostHook removes a post hook

func RemovePreHook

func RemovePreHook(hook PreHook)

RemovePreHook removes a pre hook

func Start

func Start(handler interface{})

Start wraps the handler and starts the AWS lambda handler TODO: do we need this here?

func Wrap

func Wrap(handlerFunc interface{}) lambda.Handler

Wrap wraps the handler so the agent can intercept and record events Processes the handler according to the lambda rules below: Rules:

  • handler must be a function
  • handler may take between 0 and two arguments.
  • if there are two arguments, the first argument must satisfy the "context.Context" interface.
  • handler may return between 0 and two arguments.
  • if there are two return values, the second argument must be an error.
  • if there is one return value it must be an error.

Valid function signatures:

func ()
func () error
func (TIn) error
func () (TOut, error)
func (TIn) (TOut, error)
func (context.Context) error
func (context.Context, TIn) error
func (context.Context) (TOut, error)
func (context.Context, TIn) (TOut, error)

Where "TIn" and "TOut" are types compatible with the "encoding/json" standard library. See https://golang.org/pkg/encoding/json/#Unmarshal for how deserialization behaves

Types

type Option added in v0.1.0

type Option func() error

Option is an option to override defaults

func WithDeadlineCushion added in v0.1.0

func WithDeadlineCushion(d time.Duration) Option

WithDeadlineCushion overrides the default deadline cushion with given cushion

func WithPostHooks added in v0.1.0

func WithPostHooks(hooks ...PostHook) Option

WithPostHooks adds a list of post hooks in the order they are provided

func WithPreHooks added in v0.1.0

func WithPreHooks(hooks ...PreHook) Option

WithPreHooks adds a list of pre hooks in the order they are provided

func WithStarterFunc added in v0.1.0

func WithStarterFunc(fn func(lambda.Handler)) Option

WithStarterFunc overrides the default starter function with given function

type PostHook

type PostHook interface {

	// AfterExecution executes once handler has executed
	AfterExecution(
		ctx context.Context,
		payload []byte,
		newPayload []byte,
		returnValue interface{},
		errorValue interface{},
	)
}

PostHook is a hook that's invoked after the handler has executed

type PreHook

type PreHook interface {

	// BeforeExecution executes before the handler is executed
	// You may modify the context and/or payload at this point and the modified
	// context and payload will be passed on to the handler
	BeforeExecution(
		ctx context.Context,
		payload []byte,
	) (context.Context, []byte)
}

PreHook is a hook that's invoked before the handler is executed

Jump to

Keyboard shortcuts

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