containers

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandableLambdaFunction

type CommandableLambdaFunction struct {
	*LambdaFunction
}

Abstract AWS Lambda function, that acts as a container to instantiate and run components and expose them via external entry point. All actions are automatically generated for commands defined in ICommandable components. Each command is exposed as an action defined by "cmd" parameter.

Container configuration for this Lambda function is stored in "./config/config.yml" file. But this path can be overriden by CONFIG_PATH environment variable.

Configuration parameters ###

  • dependencies:
  • controller: override for Controller dependency
  • connections:
  • discovery_key: (optional) a key to retrieve the connection from IDiscovery
  • region: (optional) AWS region
  • credentials:
  • store_key: (optional) a key to retrieve the credentials from ICredentialStore
  • access_id: AWS access/client id
  • access_key: AWS access/client id

References

  • \*:logger:\*:\*:1.0 (optional) ILogger components to pass log messages
  • \*:counters:\*:\*:1.0 (optional) ICounters components to pass collected measurements
  • \*:discovery:\*:\*:1.0 (optional) IDiscovery services to resolve connection
  • \*:credential-store:\*:\*:1.0 (optional) Credential stores to resolve credentials
  • \*:service:awslambda:\*:1.0 (optional) ILambdaService services to handle action requests
  • \*:service:commandable-awslambda:\*:1.0 (optional) ILambdaService services to handle action requests

See LambdaClient

Example:

type MyCommandableLambdaFunction struct {
	*awscont.CommandableLambdaFunction
}

func NewMyCommandableLambdaFunction() *MyCommandableLambdaFunction {
	c := &MyCommandableLambdaFunction{}
	c.CommandableLambdaFunction = awscont.NewCommandableLambdaFunction("my_group", "My data lambda function")

	c.DependencyResolver.Put(context.Background(), "controller", cref.NewDescriptor("my-group", "controller", "default", "*", "*"))
	c.AddFactory(awstest.NewDummyFactory())
	return c
}

lambda := NewMyCommandableLambdaFunction();

lambda.Run(context.Context())

func NewCommandableLambdaFunction

func NewCommandableLambdaFunction(name string, description string) *CommandableLambdaFunction

Creates a new instance of this lambda function.

  • name (optional) a container name (accessible via ContextInfo)
  • description (optional) a container description (accessible via ContextInfo)

func (*CommandableLambdaFunction) Register

func (c *CommandableLambdaFunction) Register()

Registers all actions in this lambda function.

type ILambdaFunctionOverrides

type ILambdaFunctionOverrides interface {
	cref.IReferenceable
	// Perform required registration steps.
	Register()
}

type LambdaFunction

type LambdaFunction struct {
	*cproc.Container
	Overrides ILambdaFunctionOverrides

	// The dependency resolver.
	DependencyResolver *cref.DependencyResolver
	// contains filtered or unexported fields
}

Abstract AWS Lambda function, that acts as a container to instantiate and run components and expose them via external entry point.

When handling calls "cmd" parameter determines which what action shall be called, while other parameters are passed to the action itself.

Container configuration for this Lambda function is stored in "./config/config.yml" file. But this path can be overriden by CONFIG_PATH environment variable.

Configuration parameters

  • dependencies:
  • controller: override for Controller dependency
  • connections:
  • discovery_key: (optional) a key to retrieve the connection from IDiscovery
  • region: (optional) AWS region
  • credentials:
  • store_key: (optional) a key to retrieve the credentials from ICredentialStore
  • access_id: AWS access/client id
  • access_key: AWS access/client id

References

  • \*:logger:\*:\*:1.0 (optional) ILogger components to pass log messages
  • \*:counters:\*:\*:1.0 (optional) ICounters components to pass collected measurements
  • \*:discovery:\*:\*:1.0 (optional) IDiscovery services to resolve connection
  • \*:credential-store:\*:\*:1.0 (optional) Credential stores to resolve credentials

See LambdaClient

Example:

type MyLambdaFunction struct {
	*awscont.LambdaFunction
	controller awstest.IMyController
}

func NewMyLambdaFunction() *MyLambdaFunction {
	c := &MyLambdaFunction{}
	c.LambdaFunction = awscont.InheriteLambdaFunction(c, "mygroup", "MyGroup lambda function")

	c.DependencyResolver.Put(context.Background(), "controller", cref.NewDescriptor("mygroup", "controller", "*", "*", "1.0"))
	return c
}

func (c *MyLambdaFunction) SetReferences(ctx context.Context, references cref.IReferences) {
	c.LambdaFunction.SetReferences(ctx, references)
	depRes, depErr := c.DependencyResolver.GetOneRequired("controller")
	if depErr == nil && depRes != nil {
		c.controller = depRes.(awstest.IMyController)
	}
}

func (c *MyLambdaFunction) getOneById(ctx context.Context, params map[string]any) (any, error) {
	correlationId, _ := params["correlation_id"].(string)
	return c.controller.GetOneById(
		ctx,
		correlationId,
		params["mydata_id"].(string),
	)
}

func (c *MyLambdaFunction) Register() {

	c.RegisterAction(
		"get_mydata_by_id",
		cvalid.NewObjectSchema().
			WithOptionalProperty("mydata_id", cconv.String).Schema,
		c.getOneById)
}

lambda := NewMyLambdaFunction();

lambda.Run(context.Context())

func InheriteLambdaFunction

func InheriteLambdaFunction(overrides ILambdaFunctionOverrides, name string, description string) *LambdaFunction

Creates a new instance of this lambda function. - overrides Lambda function register instance. - name (optional) a container name (accessible via ContextInfo) - description (optional) a container description (accessible via ContextInfo)

func (*LambdaFunction) Act

func (c *LambdaFunction) Act(params map[string]any) (string, error)

Calls registered action in this lambda function. "cmd" parameter in the action parameters determin what action shall be called.

This method shall only be used in testing.

  • params action parameters.
  • callback callback function that receives action result or error.

func (*LambdaFunction) GetHandler

func (c *LambdaFunction) GetHandler() func(ctx context.Context, event map[string]any) (string, error)

Gets entry point into this lambda function.

  • event an incoming event object with invocation parameters.
  • context a context object with local references.

func (*LambdaFunction) Handler

func (c *LambdaFunction) Handler(ctx context.Context, event map[string]any) (string, error)

func (*LambdaFunction) Instrument

func (c *LambdaFunction) Instrument(ctx context.Context, correlationId string, name string) *rpcserv.InstrumentTiming

Adds instrumentation to log calls and measure call time. It returns a Timing object that is used to end the time measurement. Parameters:

  • ctx context.Context operation context.
  • correlationId (optional) transaction id to trace execution through call chain.
  • name a method name.

Returns Timing object to end the time measurement.

func (*LambdaFunction) InstrumentError

func (c *LambdaFunction) InstrumentError(ctx context.Context, correlationId string, name string, errIn error,
	resIn any) (result any, err error)

InstrumentError method are adds instrumentation to error handling. Parameters:

  • ctx context.Context operation context.
  • correlationId string (optional) transaction id to trace execution through call chain.
  • name string a method name.
  • err error an occured error
  • result any (optional) an execution result

Returns: result any, err error (optional) an execution callback

func (*LambdaFunction) Open

func (c *LambdaFunction) Open(ctx context.Context, correlationId string) error
Opens the component.

Parameters:

  • ctx context.Context operation context.
  • correlationId (optional) transaction id to trace execution through call chain.

func (*LambdaFunction) RegisterAction

func (c *LambdaFunction) RegisterAction(cmd string, schema *cvalid.Schema,
	action func(ctx context.Context, params map[string]any) (result any, err error)) error

Registers an action in this lambda function.

Parameters:
	- ctx context.Context	operation context.
	- cmd           a action/command name.
	- schema        a validation schema to validate received parameters.
	- action        an action function that is called when action is invoked.

func (*LambdaFunction) RegisterServices

func (c *LambdaFunction) RegisterServices()

Registers all lambda services in the container.

func (*LambdaFunction) Run

func (c *LambdaFunction) Run(ctx context.Context) error

Runs this lambda function, loads container configuration, instantiate components and manage their lifecycle, makes this function ready to access action calls. Parameters:

  • ctx context.Context operation context.

func (*LambdaFunction) SetReferences

func (c *LambdaFunction) SetReferences(ctx context.Context, references cref.IReferences)

Sets references to dependent components. Parameters:

  • ctx context.Context operation context.
  • references references to locate the component dependencies.

Jump to

Keyboard shortcuts

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