lambda

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package lambda implements a plugin to run OPA as an AWS Lambda Extension.

Index

Constants

View Source
const (
	// Name is the name of the plugin
	Name = "lambda_extension"
)

Variables

This section is empty.

Functions

This section is empty.

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(awsLambdaRuntimeAPI string) *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) 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) NextEvent

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

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

func (*Client) Register

func (e *Client) Register(ctx context.Context, filename string) (*RegisterResponse, error)

Register will register the extension with the Extensions API

type Config

type Config struct {
	// The minimum time in seconds that must elapse before plugins will be triggered. Right now,
	// all plugins are triggered at once, and they all must use the same minimum threshold.
	MinimumTriggerThreshold *int `json:"minimum_trigger_threshold,omitempty"`
	// The maximum time in seconds that ALL plugins have to run. Once the timeout elapses, all plugin
	// runs will be cancelled and the lambda_extension plugin will move on to the next event.
	TriggerTimeout *int `json:"trigger_timeout,omitempty"`
	// The order, from first to last, that plugins will be started during intialization.
	PluginStartPriority *[]string `json:"plugin_start_priority,omitempty"`
	// the order, from first to last, that plugins will be stopped during shutdown.
	PluginStopPriority *[]string `json:"plugin_stop_priority,omitempty"`
}

Config represents the plugin configuration.

type EventType

type EventType string

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

const (
	// Invoke is a lambda invoke
	Invoke EventType = "INVOKE"

	// Shutdown is a shutdown event for the environment
	Shutdown EventType = "SHUTDOWN"
)

type NextEventResponse

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

NextEventResponse is the response for /event/next

type Plugin

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

Plugin implements a Lambda Extension client and controls OPA in a manner that is compatible with the Lambda Extension lifecycle. Instead of plugins being triggered periodically after a configured delay, they are triggered by this plugin after a minimum threshold of time has passed. When the minimum threshold has elapsed, the plugins will be triggered as soon as the Lambda Service indicates the next event is ready to process. This happens in parallel with the Lambda function running, so there is no guarantee that triggers will complete before the function completes its processing. The function is capable of responding to the client while the lambda extension is still triggering plugins. However, this plugin won't request the next event from the Lambda service until all triggers are complete (or timeout). This has ramifications for bundle loading and log shipping. When a bundle is changed, there will always be at least one lambda event that does not process with the new bundle. Likewise, it is possible for some logs to not ship until the Lambda shuts down from idleness (i.e. if X requests are processed before the minimum threshold of time has elapsed, then they will sit in the buffer until the next request, or when this plugin processes the lambda shutdown event).

func (*Plugin) Reconfigure

func (p *Plugin) Reconfigure(ctx context.Context, config interface{})

Reconfigure does nothing for this plugin.

func (*Plugin) Start

func (p *Plugin) Start(ctx context.Context) error

Start starts the plugin.

func (*Plugin) Stop

func (p *Plugin) Stop(ctx context.Context)

Stop stops the plugin.

type PluginFactory

type PluginFactory struct{}

PluginFactory is used by the plugin manager to create plugins and their configuration

func (*PluginFactory) New

func (p *PluginFactory) New(manager *plugins.Manager, config interface{}) plugins.Plugin

New creates a new instances of the lambda extension plugin.

func (*PluginFactory) Validate

func (p *PluginFactory) Validate(manager *plugins.Manager, config []byte) (interface{}, error)

Validate validates configuration and populates defaults as needed

type RegisterResponse

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

RegisterResponse 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

Jump to

Keyboard shortcuts

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