lambda

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LambdaTelemetryEndpoint = "2022-07-01/telemetry"
	LambdaExtensionEndpoint = "2020-01-01/extension"
)
View Source
const (
	SchemaVersion20220701 = "2022-07-01"
	SchemaVersionLatest   = SchemaVersion20220701
)
View Source
const (
	InitTimeout     = 5 * time.Second
	ShutdownTimeout = 1500 * time.Millisecond
	KillTimeout     = 100 * time.Millisecond
)
View Source
const DefaultHttpListenerPort = "6060"

DefaultHttpListenerPort is used to set the URL where the logs will be sent by Telemetry API

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferingCfg

type BufferingCfg struct {
	// MaxItems is the maximum number of events to be buffered in memory. (default: 10000, minimum: 1000, maximum: 10000)
	MaxItems uint32 `json:"maxItems"`
	// MaxBytes is the maximum size in bytes of the logs to be buffered in memory. (default: 262144, minimum: 262144, maximum: 1048576)
	MaxBytes uint32 `json:"maxBytes"`
	// TimeoutMS is the maximum time (in milliseconds) for a batch to be buffered. (default: 1000, minimum: 100, maximum: 30000)
	TimeoutMS uint32 `json:"timeoutMs"`
}

BufferingCfg is the configuration set for receiving logs from Logs API. Whichever of the conditions below is met first, the logs will be sent

type Client

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

Client is the client used to interact with the Lambda API Endpoints

func NewClient

func NewClient(awsLambdaRuntimeAPI string) *Client

NewClient returns a Lambda API client

func (*Client) InitError

func (e *Client) InitError(ctx context.Context, extensionId string, errorType FunctionErrorType, lambdaError LambdaError) error

InitError is used to report an Initialization Error to lambda

func (*Client) NextEvent

func (e *Client) NextEvent(ctx context.Context, extensionId string) (ExtensionEventType, []byte, 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) (string, *RegisterResponse, error)

Register will register the extension with the Extensions API

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context, logTypes []string, bufferingCfg BufferingCfg, extensionId string) error

Subscribe calls the Telemetry API to subscribe for the log events.

type DefaultClient

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

func NewAWSClient

func NewAWSClient(region string) (*DefaultClient, error)

func (*DefaultClient) GetFunction added in v0.0.3

func (c *DefaultClient) GetFunction(functionARN string) (*lambda.GetFunctionOutput, error)

type Destination

type Destination struct {
	Protocol HttpProtocol `json:"protocol"`
	URI      URI          `json:"URI"`
}

Destination is the configuration for listeners who would like to receive logs with HTTP

type EventType

type EventType string
const (
	PlatformInitStart             EventType = "platform.initStart"
	PlatformInitRuntimeDone       EventType = "platform.initRuntimeDone"
	PlatformInitReport            EventType = "platform.initReport"
	PlatformStart                 EventType = "platform.start"
	PlatformRuntimeDone           EventType = "platform.runtimeDone" // RuntimeDone event is sent when lambda function is finished it's execution
	PlatformReport                EventType = "platform.report"
	PlatformRestoreStart          EventType = "platform.restoreStart"
	PlatformRestoreRuntimeDone    EventType = "platform.restoreRuntimeDone"
	PlatformRestoreReport         EventType = "platform.restoreReport"
	PlatformTelemetrySubscription EventType = "platform.telemetrySubscription"
	PlatformLogsDropped           EventType = "platform.logsDropped"
	Function                      EventType = "function"
	Extension                     EventType = "extension"
)

type ExtensionEventType

type ExtensionEventType string

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

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

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

type FunctionErrorType

type FunctionErrorType string
const (
	SubscribeError FunctionErrorType = "Extension.SubscribeError"
	RegisterError  FunctionErrorType = "Extension.RegisterError"
	ConfigError    FunctionErrorType = "Extension.ConfigError"
	ClientError    FunctionErrorType = "Extension.ClientError"
)

type HttpProtocol

type HttpProtocol string

HttpProtocol is used to specify the protocol when subscribing to Logs API for HTTP

const (
	HttpProto HttpProtocol = "HTTP"
)

type InvokeEvent

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

func GetInvokeEvent

func GetInvokeEvent(body []byte) (*InvokeEvent, error)

type LambdaError

type LambdaError struct {
	Message string `json:"errorMessage"`
	Type    string `json:"errorType"`
}

type LambdaEvent

type LambdaEvent struct {
	EventTime string      `json:"time"`
	EventType EventType   `json:"type"`
	Record    interface{} `json:"record"`
}

type NextEvent

type NextEvent struct {
	EventType ExtensionEventType `json:"eventType"`
}

NextEvent is the response for /event/next

type RegisterResponse

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

RegisterResponse is the body of the response for /register

type SchemaVersion

type SchemaVersion string

type ShutdownEvent

type ShutdownEvent struct {
	DeadlineMs     int64              `json:"deadlineMs"`
	ShutdownReason ShutdownReasonType `json:"shutdownReason"`
}

func GetShutdownEvent

func GetShutdownEvent(body []byte) (*ShutdownEvent, error)

type ShutdownReasonType

type ShutdownReasonType string
const (
	Spindown ShutdownReasonType = "spindown"
	Timeout  ShutdownReasonType = "timeout"
	Failure  ShutdownReasonType = "failure"
)

type StatusResponse

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

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

type SubscribeRequest

type SubscribeRequest struct {
	SchemaVersion SchemaVersion `json:"schemaVersion"`
	LogTypes      []string      `json:"types"`
	BufferingCfg  BufferingCfg  `json:"buffering"`
	Destination   Destination   `json:"destination"`
}

SubscribeRequest is the request body that is sent to Logs API on subscribe

type Tracing

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

Tracing is part of the response for /event/next

type URI

type URI string

URI is used to set the endpoint where the logs will be sent to

Jump to

Keyboard shortcuts

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