rotor

package module
v0.0.0-...-32593f2 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2017 License: Apache-2.0 Imports: 13 Imported by: 0

README

rotor

A minimalistic toolkit for developing Go applications on top of AWS Lambda. For now, the hello_world guide should provide some guidance:

Guides

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EarlyTimeout

func EarlyTimeout(shutdownTimeMillis int64) func(Handler) Handler

EarlyTimeout will cancel the lambda context millisecond before actual timeout to give handlers time to shutdown cleanly

func ResourceAttribute

func ResourceAttribute(ctx context.Context, name string) string

ResourceAttribute will retrieve a resource attribute from the context or return an empty string if not found

func ResourceAttributes

func ResourceAttributes() func(Handler) Handler

ResourceAttributes middelware will read a line specific json encoded map from the environment and make it available for reading in handlers

func RuntimeSession

func RuntimeSession(ctx context.Context) *session.Session

RuntimeSession will return a aws session from the lambda context or panic if it isn't available

func WithRuntimeSession

func WithRuntimeSession() func(Handler) Handler

WithRuntimeSession will include a line specific "runtime" aws.Session into the context that is not based on native lambda credentials

Types

type GatewayHandler

type GatewayHandler struct {
	// contains filtered or unexported fields
}

GatewayHandler implements the lambda handler while allowing normal http.Handlers to serve

func NewGatewayHandler

func NewGatewayHandler(stripBasePaths int, httpH http.Handler) *GatewayHandler

NewGatewayHandler makes it easy to serve normal http

func (*GatewayHandler) HandleEvent

func (gwh *GatewayHandler) HandleEvent(ctx context.Context, msg json.RawMessage) (res interface{}, err error)

HandleEvent takes invocations from the API Gateway and turns them into http.Handler invocations

type GatewayRequest

type GatewayRequest struct {
	HTTPMethod            string
	Headers               map[string]string
	Resource              string
	PathParameters        map[string]string
	Path                  string
	QueryStringParameters map[string]string
	Body                  string
	IsBase64Encoded       bool
	StageVariables        map[string]string
}

GatewayRequest represents an Amazon API Gateway Proxy Event.

type GatewayResponse

type GatewayResponse struct {
	StatusCode int               `json:"statusCode"`
	Body       string            `json:"body"`
	Headers    map[string]string `json:"headers"`
}

GatewayResponse is returned to the API Gateway

type Handler

type Handler interface {
	HandleEvent(ctx context.Context, msg json.RawMessage) (interface{}, error)
}

Handler interface allows any type to handle lambda events

type HandlerFunc

type HandlerFunc func(ctx context.Context, msg json.RawMessage) (interface{}, error)

HandlerFunc is an adaptor that can handle

func (HandlerFunc) HandleEvent

func (h HandlerFunc) HandleEvent(ctx context.Context, msg json.RawMessage) (interface{}, error)

HandleEvent implements Handler

type Invocation

type Invocation struct {
	FunctionName          string       `json:"function_name"`
	FunctionVersion       string       `json:"function_version"`
	InvokedFunctionARN    string       `json:"invoked_function_arn"`
	MemoryLimitInMB       int          `json:"memory_limit_in_mb,string"`
	AWSRequestID          string       `json:"aws_request_id"`
	LogGroupName          string       `json:"log_group_name"`
	LogStreamName         string       `json:"log_stream_name"`
	RemainingTimeInMillis func() int64 `json:"-"`
}

Invocation provides additional information about a lambda event

func InvocationFromContext

func InvocationFromContext(ctx context.Context) (*Invocation, bool)

InvocationFromContext returns the original invocation context from a generic context

type Middleware

type Middleware func(Handler) Handler

Middleware allows plugins to manipulate the context and message passed to handlers

type Mux

type Mux struct {
	// contains filtered or unexported fields
}

Mux mutiplexes events to more specific handlers based on regexp matching of a context field

func NewMux

func NewMux() *Mux

NewMux sets up new event multiplexer

func (*Mux) Handle

func (mux *Mux) Handle(msg json.RawMessage, invoc *Invocation) (interface{}, error)

Handle mill match the invoked function arn to a specific handler

func (*Mux) MatchARN

func (mux *Mux) MatchARN(exp *regexp.Regexp, h Handler)

MatchARN adds a handler to the multiplexer that will be called when a caller matches the ARN of the invoked lambda function

func (*Mux) Use

func (mux *Mux) Use(mw Middleware)

Use adds a middleware to the lambda handler

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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