extension

package
v0.0.0-...-505e376 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(handler Handler, events ...EventType) error

Types

type Client

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

Client is a simple client for the Lambda Extensions API

func NewClient

func NewClient() *Client

NewClient returns a Lambda Extensions API client

func (*Client) ExitError

func (e *Client) ExitError(ctx context.Context, errorType string) (*StatusResponse, error)

ExitError reports an error to the platform before exiting. Call it when you encounter an unexpected failure

func (*Client) ExtensionID

func (c *Client) ExtensionID() string

func (*Client) InitError

func (e *Client) InitError(ctx context.Context, errorType string) (*StatusResponse, error)

InitError reports an initialization error to the platform. Call it when you registered but failed to initialize

func (*Client) Name

func (e *Client) Name() string

func (*Client) NextEvent

func (e *Client) NextEvent(ctx context.Context) (*Event, error)

NextEvent blocks while long polling for the next lambda invoke or shutdown

func (*Client) Register

func (e *Client) Register(events ...EventType) (*Register, error)

Register will register the extension with the Extensions API

type Event

type Event struct {
	EventType          EventType `json:"eventType"`
	DeadlineMs         int64     `json:"deadlineMs"`
	RequestID          string    `json:"requestId"`
	InvokedFunctionArn string    `json:"invokedFunctionArn"`
	Tracing            Tracing   `json:"tracing"`
}

Event is the response for /event/next

func (*Event) Deadline

func (r *Event) Deadline() time.Time

func (*Event) Timeout

func (r *Event) Timeout() time.Duration

type EventType

type EventType string

EventType represents the type of events recieved from /event/next

const (
	Invoke   EventType = "INVOKE"   // Invoke is a lambda invoke
	Shutdown EventType = "SHUTDOWN" // Shutdown is a shutdown event for the environment

)

type Handler

type Handler interface {
	Init(*Register) error
	Invoke(*Event) error
	Shutdown(*Event) error
}

type Register

type Register struct {
	FunctionName    string `json:"functionName"`
	FunctionVersion string `json:"functionVersion"`
	Handler         string `json:"handler"`
	ExtensionID     string
}

Register is the body of the response for /register

type StatusResponse

type StatusResponse struct {
	Status string `json:"status"`
}

StatusResponse is the body of the response for /init/error and /exit/error

type Tracing

type Tracing struct {
	Type  string `json:"type"`
	Value string `json:"value"`
}

Tracing is part of the response for /event/next

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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