lambda

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package lambda provides Lambda service emulation for kumo.

Index

Constants

View Source
const (
	ErrResourceNotFound      = "ResourceNotFoundException"
	ErrResourceConflict      = "ResourceConflictException"
	ErrInvalidParameterValue = "InvalidParameterValueException"
	ErrServiceException      = "ServiceException"
)

Error codes for Lambda.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateEventSourceMappingRequest

type CreateEventSourceMappingRequest struct {
	FunctionName                   string `json:"FunctionName"`
	EventSourceArn                 string `json:"EventSourceArn,omitempty"`
	BatchSize                      int    `json:"BatchSize,omitempty"`
	MaximumBatchingWindowInSeconds int    `json:"MaximumBatchingWindowInSeconds,omitempty"`
	Enabled                        *bool  `json:"Enabled,omitempty"`
}

CreateEventSourceMappingRequest is the request for CreateEventSourceMapping.

type CreateFunctionRequest

type CreateFunctionRequest struct {
	FunctionName   string            `json:"FunctionName"`
	Runtime        string            `json:"Runtime,omitempty"`
	Role           string            `json:"Role"`
	Handler        string            `json:"Handler,omitempty"`
	Code           FunctionCode      `json:"Code"`
	Description    string            `json:"Description,omitempty"`
	Timeout        int               `json:"Timeout,omitempty"`
	MemorySize     int               `json:"MemorySize,omitempty"`
	Publish        bool              `json:"Publish,omitempty"`
	PackageType    string            `json:"PackageType,omitempty"`
	Architectures  []string          `json:"Architectures,omitempty"`
	Environment    *Environment      `json:"Environment,omitempty"`
	Tags           map[string]string `json:"Tags,omitempty"`
	InvokeEndpoint string            `json:"InvokeEndpoint,omitempty"` // kumo extension
}

CreateFunctionRequest is the request for CreateFunction.

type CreateFunctionResponse

type CreateFunctionResponse struct {
	FunctionName    string       `json:"FunctionName"`
	FunctionArn     string       `json:"FunctionArn"`
	Runtime         string       `json:"Runtime,omitempty"`
	Role            string       `json:"Role"`
	Handler         string       `json:"Handler,omitempty"`
	CodeSize        int64        `json:"CodeSize"`
	Description     string       `json:"Description,omitempty"`
	Timeout         int          `json:"Timeout"`
	MemorySize      int          `json:"MemorySize"`
	LastModified    string       `json:"LastModified"`
	CodeSha256      string       `json:"CodeSha256"`
	Version         string       `json:"Version"`
	State           string       `json:"State,omitempty"`
	StateReason     string       `json:"StateReason,omitempty"`
	StateReasonCode string       `json:"StateReasonCode,omitempty"`
	PackageType     string       `json:"PackageType,omitempty"`
	Architectures   []string     `json:"Architectures,omitempty"`
	Environment     *Environment `json:"Environment,omitempty"`
}

CreateFunctionResponse is the response for CreateFunction.

type Environment

type Environment struct {
	Variables map[string]string `json:"Variables,omitempty"`
}

Environment represents the function's environment variables.

type EventSourceMapping

type EventSourceMapping struct {
	UUID                           string  `json:"UUID"`
	FunctionArn                    string  `json:"FunctionArn"`
	EventSourceArn                 string  `json:"EventSourceArn,omitempty"`
	State                          string  `json:"State"`
	StateTransitionReason          string  `json:"StateTransitionReason,omitempty"`
	BatchSize                      int     `json:"BatchSize,omitempty"`
	MaximumBatchingWindowInSeconds int     `json:"MaximumBatchingWindowInSeconds,omitempty"`
	Enabled                        *bool   `json:"Enabled,omitempty"`
	LastModified                   float64 `json:"LastModified,omitempty"`
	LastProcessingResult           string  `json:"LastProcessingResult,omitempty"`
}

EventSourceMapping represents a Lambda event source mapping.

type Function

type Function struct {
	FunctionName    string
	FunctionArn     string
	Runtime         string
	Role            string
	Handler         string
	Description     string
	Timeout         int
	MemorySize      int
	CodeSize        int64
	CodeSha256      string
	Version         string
	LastModified    time.Time
	State           string
	StateReason     string
	StateReasonCode string
	PackageType     string
	Architectures   []string
	Environment     *Environment
	Code            *FunctionCode
	Tags            map[string]string
	Policy          *ResourcePolicy
	InvokeEndpoint  string // kumo extension: HTTP endpoint to proxy invocations
}

Function represents a Lambda function.

type FunctionCode

type FunctionCode struct {
	ZipFile         []byte `json:"ZipFile,omitempty"`
	S3Bucket        string `json:"S3Bucket,omitempty"`
	S3Key           string `json:"S3Key,omitempty"`
	S3ObjectVersion string `json:"S3ObjectVersion,omitempty"`
	ImageURI        string `json:"ImageURI,omitempty"`
}

FunctionCode represents the function's code.

type FunctionCodeLocation

type FunctionCodeLocation struct {
	RepositoryType string `json:"RepositoryType,omitempty"`
	Location       string `json:"Location,omitempty"`
}

FunctionCodeLocation contains the location of the function code.

type FunctionConfiguration

type FunctionConfiguration struct {
	FunctionName    string       `json:"FunctionName"`
	FunctionArn     string       `json:"FunctionArn"`
	Runtime         string       `json:"Runtime,omitempty"`
	Role            string       `json:"Role"`
	Handler         string       `json:"Handler,omitempty"`
	CodeSize        int64        `json:"CodeSize"`
	Description     string       `json:"Description,omitempty"`
	Timeout         int          `json:"Timeout"`
	MemorySize      int          `json:"MemorySize"`
	LastModified    string       `json:"LastModified"`
	CodeSha256      string       `json:"CodeSha256"`
	Version         string       `json:"Version"`
	State           string       `json:"State,omitempty"`
	StateReason     string       `json:"StateReason,omitempty"`
	StateReasonCode string       `json:"StateReasonCode,omitempty"`
	PackageType     string       `json:"PackageType,omitempty"`
	Architectures   []string     `json:"Architectures,omitempty"`
	Environment     *Environment `json:"Environment,omitempty"`
}

FunctionConfiguration contains function configuration details.

type FunctionError

type FunctionError struct {
	Type    string `json:"Type"`
	Message string `json:"Message"`
}

FunctionError represents a Lambda error.

func (*FunctionError) Error

func (e *FunctionError) Error() string

Error implements the error interface.

type GetFunctionResponse

type GetFunctionResponse struct {
	Configuration *FunctionConfiguration `json:"Configuration"`
	Code          *FunctionCodeLocation  `json:"Code,omitempty"`
	Tags          map[string]string      `json:"Tags,omitempty"`
}

GetFunctionResponse is the response for GetFunction.

type InvokeRequest

type InvokeRequest struct {
	Payload        []byte `json:"-"`
	InvocationType string `json:"-"`
	LogType        string `json:"-"`
	ClientContext  string `json:"-"`
	Qualifier      string `json:"-"`
}

InvokeRequest is the request for Invoke.

type InvokeResponse

type InvokeResponse struct {
	StatusCode      int    `json:"-"`
	FunctionError   string `json:"-"`
	LogResult       string `json:"-"`
	Payload         []byte `json:"-"`
	ExecutedVersion string `json:"-"`
}

InvokeResponse is the response for Invoke.

type ListEventSourceMappingsResponse

type ListEventSourceMappingsResponse struct {
	EventSourceMappings []*EventSourceMapping `json:"EventSourceMappings"`
	NextMarker          string                `json:"NextMarker,omitempty"`
}

ListEventSourceMappingsResponse is the response for ListEventSourceMappings.

type ListFunctionsResponse

type ListFunctionsResponse struct {
	Functions  []*FunctionConfiguration `json:"Functions"`
	NextMarker string                   `json:"NextMarker,omitempty"`
}

ListFunctionsResponse is the response for ListFunctions.

type MemoryStorage

type MemoryStorage struct {
	Functions           map[string]*Function           `json:"functions"`
	EventSourceMappings map[string]*EventSourceMapping `json:"eventSourceMappings"`
	// contains filtered or unexported fields
}

MemoryStorage implements Storage with in-memory data.

func NewMemoryStorage

func NewMemoryStorage(baseURL string, opts ...Option) *MemoryStorage

NewMemoryStorage creates a new in-memory storage.

func (*MemoryStorage) AddPermission added in v0.21.0

func (s *MemoryStorage) AddPermission(_ context.Context, functionName string, stmt *PolicyStatement) error

AddPermission adds a statement to a function's resource policy.

func (*MemoryStorage) Close added in v0.6.0

func (s *MemoryStorage) Close() error

Close saves the storage state to disk if persistence is enabled.

func (*MemoryStorage) CreateEventSourceMapping

func (s *MemoryStorage) CreateEventSourceMapping(_ context.Context, req *CreateEventSourceMappingRequest) (*EventSourceMapping, error)

CreateEventSourceMapping creates a new event source mapping.

func (*MemoryStorage) CreateFunction

func (s *MemoryStorage) CreateFunction(_ context.Context, req *CreateFunctionRequest) (*Function, error)

CreateFunction creates a new Lambda function.

func (*MemoryStorage) DeleteEventSourceMapping

func (s *MemoryStorage) DeleteEventSourceMapping(_ context.Context, uuid string) error

DeleteEventSourceMapping deletes an event source mapping.

func (*MemoryStorage) DeleteFunction

func (s *MemoryStorage) DeleteFunction(_ context.Context, name string) error

DeleteFunction deletes a Lambda function.

func (*MemoryStorage) GetEventSourceMapping

func (s *MemoryStorage) GetEventSourceMapping(_ context.Context, uuid string) (*EventSourceMapping, error)

GetEventSourceMapping retrieves an event source mapping by UUID.

func (*MemoryStorage) GetFunction

func (s *MemoryStorage) GetFunction(_ context.Context, name string) (*Function, error)

GetFunction retrieves a Lambda function by name.

func (*MemoryStorage) GetFunctionByARN added in v0.21.0

func (s *MemoryStorage) GetFunctionByARN(_ context.Context, arn string) (*Function, error)

GetFunctionByARN retrieves a Lambda function by its ARN.

func (*MemoryStorage) GetFunctionCodeSigningConfig added in v0.22.0

func (s *MemoryStorage) GetFunctionCodeSigningConfig(_ context.Context, functionName string) (string, error)

GetFunctionCodeSigningConfig returns the code signing config ARN for a function.

func (*MemoryStorage) GetPolicy added in v0.22.0

func (s *MemoryStorage) GetPolicy(_ context.Context, functionName string) (*ResourcePolicy, error)

GetPolicy returns the resource policy for a function.

func (*MemoryStorage) ListAliases added in v0.22.0

func (s *MemoryStorage) ListAliases(_ context.Context, functionName string) error

ListAliases validates the function exists for alias listing.

func (*MemoryStorage) ListEventSourceMappings

func (s *MemoryStorage) ListEventSourceMappings(_ context.Context, functionName, eventSourceArn, marker string, maxItems int) ([]*EventSourceMapping, string, error)

ListEventSourceMappings lists event source mappings with optional filters.

func (*MemoryStorage) ListFunctionEventInvokeConfigs added in v0.22.0

func (s *MemoryStorage) ListFunctionEventInvokeConfigs(_ context.Context, functionName string) error

ListFunctionEventInvokeConfigs validates the function exists for event invoke config listing.

func (*MemoryStorage) ListFunctions

func (s *MemoryStorage) ListFunctions(_ context.Context, marker string, maxItems int) ([]*Function, string, error)

ListFunctions lists all Lambda functions.

func (*MemoryStorage) ListTags added in v0.22.0

func (s *MemoryStorage) ListTags(_ context.Context, arn string) (map[string]string, error)

ListTags returns the tags for a function identified by its ARN.

func (*MemoryStorage) ListVersionsByFunction added in v0.22.0

func (s *MemoryStorage) ListVersionsByFunction(_ context.Context, functionName string) (*Function, error)

ListVersionsByFunction returns the function for version listing.

func (*MemoryStorage) MarshalJSON added in v0.6.0

func (s *MemoryStorage) MarshalJSON() ([]byte, error)

MarshalJSON serializes the storage state to JSON.

func (*MemoryStorage) RemovePermission added in v0.21.0

func (s *MemoryStorage) RemovePermission(_ context.Context, functionName, statementID string) error

RemovePermission removes a statement from a function's resource policy.

func (*MemoryStorage) TagResource added in v0.22.0

func (s *MemoryStorage) TagResource(_ context.Context, arn string, tags map[string]string) error

TagResource adds or overwrites tags on a function identified by its ARN.

func (*MemoryStorage) UnmarshalJSON added in v0.6.0

func (s *MemoryStorage) UnmarshalJSON(data []byte) error

UnmarshalJSON restores the storage state from JSON.

func (*MemoryStorage) UntagResource added in v0.22.0

func (s *MemoryStorage) UntagResource(_ context.Context, arn string, tagKeys []string) error

UntagResource removes tags from a function identified by its ARN.

func (*MemoryStorage) UpdateEventSourceMapping

func (s *MemoryStorage) UpdateEventSourceMapping(_ context.Context, uuid string, req *UpdateEventSourceMappingRequest) (*EventSourceMapping, error)

UpdateEventSourceMapping updates an event source mapping.

func (*MemoryStorage) UpdateFunctionCode

func (s *MemoryStorage) UpdateFunctionCode(_ context.Context, name string, req *UpdateFunctionCodeRequest) (*Function, error)

UpdateFunctionCode updates the code of a Lambda function.

func (*MemoryStorage) UpdateFunctionConfiguration

func (s *MemoryStorage) UpdateFunctionConfiguration(_ context.Context, name string, req *UpdateFunctionConfigurationRequest) (*Function, error)

UpdateFunctionConfiguration updates the configuration of a Lambda function.

type Option added in v0.6.0

type Option func(*MemoryStorage)

Option is a configuration option for MemoryStorage.

func WithDataDir added in v0.6.0

func WithDataDir(dir string) Option

WithDataDir enables persistent storage in the specified directory.

type PolicyStatement added in v0.21.0

type PolicyStatement struct {
	Sid       string            `json:"Sid"`
	Effect    string            `json:"Effect"`
	Principal map[string]string `json:"Principal"`
	Action    string            `json:"Action"`
	Resource  string            `json:"Resource"`
	Condition map[string]any    `json:"Condition,omitempty"`
}

PolicyStatement represents a single statement in a resource policy.

type ResourcePolicy added in v0.21.0

type ResourcePolicy struct {
	Version    string             `json:"Version"`
	ID         string             `json:"Id"`
	Statements []*PolicyStatement `json:"Statement"`
}

ResourcePolicy represents a Lambda function resource policy.

type Service

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

Service implements the Lambda service.

func New

func New(storage Storage, baseURL string) *Service

New creates a new Lambda service.

func (*Service) AddPermission added in v0.21.0

func (s *Service) AddPermission(w http.ResponseWriter, r *http.Request)

AddPermission adds a permission to a Lambda function's resource policy.

func (*Service) Close added in v0.6.0

func (s *Service) Close() error

Close saves the storage state if persistence is enabled.

func (*Service) CreateEventSourceMapping

func (s *Service) CreateEventSourceMapping(w http.ResponseWriter, r *http.Request)

CreateEventSourceMapping handles the CreateEventSourceMapping API.

func (*Service) CreateFunction

func (s *Service) CreateFunction(w http.ResponseWriter, r *http.Request)

CreateFunction handles the CreateFunction API.

func (*Service) DeleteEventSourceMapping

func (s *Service) DeleteEventSourceMapping(w http.ResponseWriter, r *http.Request)

DeleteEventSourceMapping handles the DeleteEventSourceMapping API.

func (*Service) DeleteFunction

func (s *Service) DeleteFunction(w http.ResponseWriter, r *http.Request)

DeleteFunction handles the DeleteFunction API.

func (*Service) GetEventSourceMapping

func (s *Service) GetEventSourceMapping(w http.ResponseWriter, r *http.Request)

GetEventSourceMapping handles the GetEventSourceMapping API.

func (*Service) GetFunction

func (s *Service) GetFunction(w http.ResponseWriter, r *http.Request)

GetFunction handles the GetFunction API.

func (*Service) GetFunctionCodeSigningConfig added in v0.19.0

func (s *Service) GetFunctionCodeSigningConfig(w http.ResponseWriter, r *http.Request)

GetFunctionCodeSigningConfig reports no code-signing config for any function. terraform-provider-aws reads this on every refresh.

func (*Service) GetFunctionConfiguration added in v0.21.0

func (s *Service) GetFunctionConfiguration(w http.ResponseWriter, r *http.Request)

GetFunctionConfiguration handles GET /functions/{name}/configuration. Returns only the configuration portion of GetFunction.

func (*Service) GetPolicy added in v0.19.0

func (s *Service) GetPolicy(w http.ResponseWriter, r *http.Request)

GetPolicy returns the resource policy for a function. AWS returns 404 when a function has no attached policy; terraform-provider-aws expects that and treats it as "no policy".

func (*Service) Invoke

func (s *Service) Invoke(w http.ResponseWriter, r *http.Request)

Invoke handles the Invoke API.

func (*Service) ListAliases added in v0.19.0

func (s *Service) ListAliases(w http.ResponseWriter, r *http.Request)

ListAliases returns an empty Aliases list. terraform-provider-aws calls this on every refresh of aws_lambda_function. Aliases are not modeled.

func (*Service) ListEventSourceMappings

func (s *Service) ListEventSourceMappings(w http.ResponseWriter, r *http.Request)

ListEventSourceMappings handles the ListEventSourceMappings API.

func (*Service) ListFunctionEventInvokeConfigs added in v0.19.0

func (s *Service) ListFunctionEventInvokeConfigs(w http.ResponseWriter, r *http.Request)

ListFunctionEventInvokeConfigs returns an empty list.

func (*Service) ListFunctions

func (s *Service) ListFunctions(w http.ResponseWriter, r *http.Request)

ListFunctions handles the ListFunctions API.

func (*Service) ListTags added in v0.21.0

func (s *Service) ListTags(w http.ResponseWriter, r *http.Request)

ListTags returns the tags for a Lambda function identified by its ARN. The AWS API path is GET /2017-03-31/tags/{ARN}.

func (*Service) ListVersionsByFunction added in v0.19.0

func (s *Service) ListVersionsByFunction(w http.ResponseWriter, r *http.Request)

ListVersionsByFunction returns a single $LATEST entry for any existing function. terraform-provider-aws calls this on every refresh of aws_lambda_function and apply errors immediately after CreateFunction without it.

func (*Service) Name

func (s *Service) Name() string

Name returns the service name.

func (*Service) RegisterRoutes

func (s *Service) RegisterRoutes(r service.Router)

RegisterRoutes registers the Lambda routes. Routes are registered under both /lambda/... (for SDK BaseEndpoint) and /2015-03-31/... (for CLI).

func (*Service) RemovePermission added in v0.21.0

func (s *Service) RemovePermission(w http.ResponseWriter, r *http.Request)

RemovePermission removes a permission from a Lambda function's resource policy.

func (*Service) TagResource added in v0.22.0

func (s *Service) TagResource(w http.ResponseWriter, r *http.Request)

TagResource adds or overwrites tags on a Lambda function identified by its ARN. The AWS API path is POST /2017-03-31/tags/{ARN}.

func (*Service) UntagResource added in v0.22.0

func (s *Service) UntagResource(w http.ResponseWriter, r *http.Request)

UntagResource removes tags from a Lambda function identified by its ARN. The AWS API path is DELETE /2017-03-31/tags/{ARN}?tagKeys=key1&tagKeys=key2.

func (*Service) UpdateEventSourceMapping

func (s *Service) UpdateEventSourceMapping(w http.ResponseWriter, r *http.Request)

UpdateEventSourceMapping handles the UpdateEventSourceMapping API.

func (*Service) UpdateFunctionCode

func (s *Service) UpdateFunctionCode(w http.ResponseWriter, r *http.Request)

UpdateFunctionCode handles the UpdateFunctionCode API.

func (*Service) UpdateFunctionConfiguration

func (s *Service) UpdateFunctionConfiguration(w http.ResponseWriter, r *http.Request)

UpdateFunctionConfiguration handles the UpdateFunctionConfiguration API.

type Storage

type Storage interface {
	CreateFunction(ctx context.Context, req *CreateFunctionRequest) (*Function, error)
	GetFunction(ctx context.Context, name string) (*Function, error)
	GetFunctionByARN(ctx context.Context, arn string) (*Function, error)
	DeleteFunction(ctx context.Context, name string) error
	ListFunctions(ctx context.Context, marker string, maxItems int) ([]*Function, string, error)
	UpdateFunctionCode(ctx context.Context, name string, req *UpdateFunctionCodeRequest) (*Function, error)
	UpdateFunctionConfiguration(ctx context.Context, name string, req *UpdateFunctionConfigurationRequest) (*Function, error)

	// Tag operations
	ListTags(ctx context.Context, arn string) (map[string]string, error)
	TagResource(ctx context.Context, arn string, tags map[string]string) error
	UntagResource(ctx context.Context, arn string, tagKeys []string) error

	// Permission operations
	AddPermission(ctx context.Context, functionName string, stmt *PolicyStatement) error
	RemovePermission(ctx context.Context, functionName, statementID string) error
	GetPolicy(ctx context.Context, functionName string) (*ResourcePolicy, error)

	// Read-only accessors
	ListVersionsByFunction(ctx context.Context, functionName string) (*Function, error)
	ListAliases(ctx context.Context, functionName string) error
	ListFunctionEventInvokeConfigs(ctx context.Context, functionName string) error
	GetFunctionCodeSigningConfig(ctx context.Context, functionName string) (string, error)

	// EventSourceMapping operations
	CreateEventSourceMapping(ctx context.Context, req *CreateEventSourceMappingRequest) (*EventSourceMapping, error)
	GetEventSourceMapping(ctx context.Context, uuid string) (*EventSourceMapping, error)
	DeleteEventSourceMapping(ctx context.Context, uuid string) error
	ListEventSourceMappings(ctx context.Context, functionName, eventSourceArn, marker string, maxItems int) ([]*EventSourceMapping, string, error)
	UpdateEventSourceMapping(ctx context.Context, uuid string, req *UpdateEventSourceMappingRequest) (*EventSourceMapping, error)
}

Storage defines the Lambda storage interface.

type UpdateEventSourceMappingRequest

type UpdateEventSourceMappingRequest struct {
	FunctionName                   string `json:"FunctionName,omitempty"`
	BatchSize                      int    `json:"BatchSize,omitempty"`
	MaximumBatchingWindowInSeconds int    `json:"MaximumBatchingWindowInSeconds,omitempty"`
	Enabled                        *bool  `json:"Enabled,omitempty"`
}

UpdateEventSourceMappingRequest is the request for UpdateEventSourceMapping.

type UpdateFunctionCodeRequest

type UpdateFunctionCodeRequest struct {
	ZipFile         []byte   `json:"ZipFile,omitempty"`
	S3Bucket        string   `json:"S3Bucket,omitempty"`
	S3Key           string   `json:"S3Key,omitempty"`
	S3ObjectVersion string   `json:"S3ObjectVersion,omitempty"`
	ImageURI        string   `json:"ImageURI,omitempty"`
	Publish         bool     `json:"Publish,omitempty"`
	Architectures   []string `json:"Architectures,omitempty"`
}

UpdateFunctionCodeRequest is the request for UpdateFunctionCode.

type UpdateFunctionConfigurationRequest

type UpdateFunctionConfigurationRequest struct {
	Description    string       `json:"Description,omitempty"`
	Handler        string       `json:"Handler,omitempty"`
	MemorySize     int          `json:"MemorySize,omitempty"`
	Role           string       `json:"Role,omitempty"`
	Runtime        string       `json:"Runtime,omitempty"`
	Timeout        int          `json:"Timeout,omitempty"`
	Environment    *Environment `json:"Environment,omitempty"`
	InvokeEndpoint string       `json:"InvokeEndpoint,omitempty"` // kumo extension
}

UpdateFunctionConfigurationRequest is the request for UpdateFunctionConfiguration.

Jump to

Keyboard shortcuts

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