clients

package
v1.1.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleLambdaResponse

func HandleLambdaResponse[T any](data *lambda.InvokeOutput) (convRes T, err error)

ConvertComandResult method helps get correct result from JSON by prototype Parameters:

  • comRes any input JSON string
  • prototype reflect.Type output object prototype

Returns: convRes any, err error

Types

type CommandableLambdaClient

type CommandableLambdaClient struct {
	*LambdaClient
	// contains filtered or unexported fields
}

Abstract client that calls commandable AWS Lambda Functions.

Commandable services are generated automatically for ICommandable objects. Each command is exposed as action determined by "cmd" parameter.

Configuration parameters

- 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

- options:

  • connect_timeout: (optional) connection timeout in milliseconds (default: 10 sec)

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 LambdaFunction

Example:

type MyLambdaClient struct {
    *CommandableLambdaClient
}

...

func (c* MyLambdaClient) GetData(ctx context.Context, correlationId string, id string)(result DataPage[MyData], err error) {

    valVal, err := c.callCommand(ctx,
          "get_data",
          correlationId,
          map[string]any{ "id": id })

    if calErr != nil {
	    return nil, calErr
	}

	defer timing.EndTiming(ctx, err)

	return awsclient.HandleLambdaResponse[cdata.DataPage[MyData]](calValue)
}

...

client := NewMyLambdaClient(); client.Configure(context.Background(), NewConfigParamsFromTuples(

"connection.region", "us-east-1",
"connection.access_id", "XXXXXXXXXXX",
"connection.access_key", "XXXXXXXXXXX",
"connection.arn", "YYYYYYYYYYYYY"

));

res, err := client.GetData(context.Background(), "123", "1") ...

func NewCommandableLambdaClient

func NewCommandableLambdaClient(name string) *CommandableLambdaClient

Creates a new instance of this client.

  • name a service name.

func (*CommandableLambdaClient) CallCommand

func (c *CommandableLambdaClient) CallCommand(ctx context.Context, cmd string, correlationId string, params map[string]any) (result *lambda.InvokeOutput, err error)

Calls a remote action in AWS Lambda function. The name of the action is added as "cmd" parameter to the action parameters.

  • ctx context.Context operation context.
  • cmd an action name
  • correlationId (optional) transaction id to trace execution through call chain.
  • params command parameters.
  • Return *lambda.InvokeOutput result or error.

type LambdaClient

type LambdaClient struct {
	// The reference to AWS Lambda Function.
	Lambda *lambda.Lambda
	// The opened flag.
	Opened bool
	// The AWS connection parameters
	Connection *awscon.AwsConnectionParams

	// The dependencies resolver.
	DependencyResolver *cref.DependencyResolver
	// The connection resolver.
	ConnectionResolver *awscon.AwsConnectionResolver
	// The logger.
	Logger *clog.CompositeLogger
	//The performance counters.
	Counters *ccount.CompositeCounters
	// The tracer.
	Tracer *ctrace.CompositeTracer
	// contains filtered or unexported fields
}

Abstract client that calls AWS Lambda Functions.

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

Configuration parameters:

  • 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
  • options:
  • connect_timeout: (optional) connection timeout in milliseconds (default: 10 sec)

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 LambdaFunction See CommandableLambdaClient

Example:

type MyLambdaClient struct  {
	*LambdaClient
	...
}

func (c* MyLambdaClient) getData(ctx context.Context, correlationId string, id string)(result MyData, err error){
	timing := c.Instrument(ctx, correlationId, "myclient.get_data");
	callRes, callErr := c.Call(ctx ,"get_data" correlationId, map[string]interface{ "id": id })
	if callErr != nil {
		return callErr
	}
	defer timing.EndTiming(ctx, nil)
	return awsclient.HandleLambdaResponse[*cdata.DataPage[MyData]](calValue)
}
...

client = NewMyLambdaClient();
client.Configure(context.Background(), NewConfigParamsFromTuples(
    "connection.region", "us-east-1",
    "connection.access_id", "XXXXXXXXXXX",
    "connection.access_key", "XXXXXXXXXXX",
    "connection.arn", "YYYYYYYYYYYYY"
))

data, err := client.GetData(context.Background(), "123", "1")
...

func NewLambdaClient

func NewLambdaClient() *LambdaClient

func (*LambdaClient) Call

func (c *LambdaClient) Call(ctx context.Context, cmd string, correlationId string, params map[string]any) (result *lambda.InvokeOutput, err error)

Calls a AWS Lambda Function action.

Parameters:
	- ctx context.Context	operation context.
	- cmd               an action name to be called.
	- correlationId     (optional) transaction id to trace execution through call chain.
	- params            (optional) action parameters.
	- Returns           result and error.

func (*LambdaClient) CallOneWay

func (c *LambdaClient) CallOneWay(ctx context.Context, cmd string, correlationId string, params map[string]any) error

Calls a AWS Lambda Function action asynchronously without waiting for response.

Parameters:
	- ctx context.Context	operation context.
	- cmd               an action name to be called.
	- correlationId     (optional) transaction id to trace execution through call chain.
	- params            (optional) action parameters.
	- Returns           error or null for success.

func (*LambdaClient) Close

func (c *LambdaClient) Close(ctx context.Context, correlationId string) error

Closes component and frees used resources.

Parameters:
	- ctx context.Context	operation context.
	- correlationId 	(optional) transaction id to trace execution through call chain.
	- Returns 			 error or null no errors occured.

func (*LambdaClient) Configure

func (c *LambdaClient) Configure(ctx context.Context, config *cconf.ConfigParams)

Configures component by passing configuration parameters.

Parameters:
	- ctx context.Context	operation context.
	- config    configuration parameters to be set.

func (*LambdaClient) Instrument

func (c *LambdaClient) Instrument(ctx context.Context, correlationId string, name string) *rpcsrv.InstrumentTiming

Instrument method are adds instrumentation to log calls and measure call time. It returns a services.InstrumentTiming object that is used to end the time measurement.

Parameters:
	- ctx context.Context	operation context.
	- correlationId string (optional) transaction id to trace execution through call chain.
	- name string a method name.
Returns: services.InstrumentTiming object to end the time measurement.

func (*LambdaClient) Invoke

func (c *LambdaClient) Invoke(ctx context.Context, invocationType string, cmd string, correlationId string, args map[string]any) (result *lambda.InvokeOutput, err error)

Performs AWS Lambda Function invocation.

Parameters:
	- ctx context.Context	operation context.
	- invocationType    an invocation type: "RequestResponse" or "Event"
	- cmd               an action name to be called.
	- correlationId 	(optional) transaction id to trace execution through call chain.
	- args              action arguments

Returns result or error.

func (*LambdaClient) IsOpen

func (c *LambdaClient) IsOpen() bool

Checks if the component is opened. Returns true if the component has been opened and false otherwise.

func (*LambdaClient) Open

func (c *LambdaClient) 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.
	- Return 			 error or nil no errors occured.

func (*LambdaClient) SetReferences

func (c *LambdaClient) 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