aws-lambda-go: Index | Files | Directories

package lambda

import ""


Package Files

entry.go function.go handler.go panic.go

func Start Uses

func Start(handler interface{})

Start takes a handler and talks to an internal Lambda endpoint to pass requests to the handler. If the handler does not match one of the supported types an appropriate error message will be returned to the caller. Start blocks, and does not return after being called.


* 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 for how deserialization behaves

func StartHandler Uses

func StartHandler(handler Handler)

StartHandler takes in a Handler wrapper interface which can be implemented either by a custom function or a struct.

Handler implementation requires a single "Invoke()" function:

func Invoke(context.Context, []byte) ([]byte, error)

type Function Uses

type Function struct {
    // contains filtered or unexported fields

Function struct which wrap the Handler

func NewFunction Uses

func NewFunction(handler Handler) *Function

NewFunction which creates a Function with a given Handler

func (*Function) Invoke Uses

func (fn *Function) Invoke(req *messages.InvokeRequest, response *messages.InvokeResponse) error

Invoke method try to perform a command given an InvokeRequest and an InvokeResponse

func (*Function) Ping Uses

func (fn *Function) Ping(req *messages.PingRequest, response *messages.PingResponse) error

Ping method which given a PingRequest and a PingResponse parses the PingResponse

type Handler Uses

type Handler interface {
    Invoke(ctx context.Context, payload []byte) ([]byte, error)

func NewHandler Uses

func NewHandler(handlerFunc interface{}) Handler

NewHandler creates a base lambda handler from the given handler function. The returned Handler performs JSON deserialization and deserialization, and delegates to the input handler function. The handler function parameter must satisfy the rules documented by Start. If handlerFunc is not a valid handler, the returned Handler simply reports the validation error.


handlertracePackage handlertrace allows middleware authors using lambda.NewHandler to instrument request and response events.

Package lambda imports 14 packages (graph) and is imported by 158 packages. Updated 2019-10-23. Refresh now. Tools for package owners.