pip-services3-aws-node
- Version 3.1.0
- Published
- 202 kB
- 4 dependencies
- MIT license
Install
npm i pip-services3-aws-node
yarn add pip-services3-aws-node
pnpm add pip-services3-aws-node
Overview
AWS-specific components for Pip.Services in Node.js
Index
Classes
Classes
class AwsConnectionParams
class AwsConnectionParams extends ConfigParams {}
Contains connection parameters to authenticate against Amazon Web Services (AWS) and connect to specific AWS resource.
The class is able to compose and parse AWS resource ARNs.
### Configuration parameters ###
- access_id: application access id - client_id: alternative to access_id - access_key: application secret key - client_key: alternative to access_key - secret_key: alternative to access_key
In addition to standard parameters [[https://pip-services3-node.github.io/pip-services3-components-node/classes/auth.credentialparams.html CredentialParams]] may contain any number of custom parameters
See Also
[[AwsConnectionResolver]]
### Example ###
let connection = AwsConnectionParams.fromTuples( "region", "us-east-1", "access_id", "XXXXXXXXXXXXXXX", "secret_key", "XXXXXXXXXXXXXXX", "service", "s3", "bucket", "mybucket" );
let region = connection.getRegion(); // Result: "us-east-1" let accessId = connection.getAccessId(); // Result: "XXXXXXXXXXXXXXX" let secretKey = connection.getAccessKey(); // Result: "XXXXXXXXXXXXXXX" let pin = connection.getAsNullableString("bucket"); // Result: "mybucket"
constructor
constructor(values?: any);
Creates an new instance of the connection parameters.
Parameter values
(optional) an object to be converted into key-value pairs to initialize this connection.
method fromConfig
static fromConfig: (config: ConfigParams) => AwsConnectionParams;
Retrieves AwsConnectionParams from configuration parameters. The values are retrieves from "connection" and "credential" sections.
Parameter config
configuration parameters
Returns
the generated AwsConnectionParams object.
See Also
[[mergeConfigs]]
method fromString
static fromString: (line: string) => AwsConnectionParams;
Creates a new AwsConnectionParams object filled with key-value pairs serialized as a string.
Parameter line
a string with serialized key-value pairs as "key1=value1;key2=value2;..." Example: "Key1=123;Key2=ABC;Key3=2016-09-16T00:00:00.00Z"
Returns
a new AwsConnectionParams object.
method getAccessId
getAccessId: () => string;
Gets the AWS access id.
Returns
the AWS access id.
method getAccessKey
getAccessKey: () => string;
Gets the AWS client key.
Returns
the AWS client key.
method getAccount
getAccount: () => string;
Gets the AWS account id.
Returns
the AWS account id.
method getArn
getArn: () => string;
Gets the AWS resource ARN. If the ARN is not defined it automatically generates it from other properties.
Returns
the AWS resource ARN.
method getPartition
getPartition: () => string;
Gets the AWS partition name.
Returns
the AWS partition name.
method getRegion
getRegion: () => string;
Gets the AWS region.
Returns
the AWS region.
method getResource
getResource: () => string;
Gets the AWS resource id.
Returns
the AWS resource id.
method getResourceType
getResourceType: () => string;
Gets the AWS resource type.
Returns
the AWS resource type.
method getService
getService: () => string;
Gets the AWS service name.
Returns
the AWS service name.
method mergeConfigs
static mergeConfigs: (...configs: ConfigParams[]) => AwsConnectionParams;
Retrieves AwsConnectionParams from multiple configuration parameters. The values are retrieves from "connection" and "credential" sections.
Parameter configs
a list with configuration parameters
Returns
the generated AwsConnectionParams object.
See Also
[[fromConfig]]
method setAccessId
setAccessId: (value: string) => void;
Sets the AWS access id.
Parameter value
the AWS access id.
method setAccessKey
setAccessKey: (value: string) => void;
Sets the AWS client key.
Parameter value
a new AWS client key.
method setAccount
setAccount: (value: string) => void;
Sets the AWS account id.
Parameter value
the AWS account id.
method setArn
setArn: (value: string) => void;
Sets the AWS resource ARN. When it sets the value, it automatically parses the ARN and sets individual parameters.
Parameter value
a new AWS resource ARN.
method setPartition
setPartition: (value: string) => void;
Sets the AWS partition name.
Parameter value
a new AWS partition name.
method setRegion
setRegion: (value: string) => void;
Sets the AWS region.
Parameter value
a new AWS region.
method setResource
setResource: (value: string) => void;
Sets the AWS resource id.
Parameter value
a new AWS resource id.
method setResourceType
setResourceType: (value: string) => void;
Sets the AWS resource type.
Parameter value
a new AWS resource type.
method setService
setService: (value: string) => void;
Sets the AWS service name.
Parameter value
a new AWS service name.
method validate
validate: (correlationId: string) => ConfigException;
Validates this connection parameters
Parameter correlationId
(optional) transaction id to trace execution through call chain.
Returns
a ConfigException or null if validation passed successfully.
class AwsConnectionResolver
class AwsConnectionResolver implements IConfigurable, IReferenceable {}
Helper class to retrieve AWS connection and credential parameters, validate them and compose a [[AwsConnectionParams]] value.
### Configuration parameters ###
- connections: - discovery_key: (optional) a key to retrieve the connection from [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] - region: (optional) AWS region - partition: (optional) AWS partition - service: (optional) AWS service - resource_type: (optional) AWS resource type - resource: (optional) AWS resource id - arn: (optional) AWS resource ARN - credentials: - store_key: (optional) a key to retrieve the credentials from [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/auth.icredentialstore.html ICredentialStore]] - access_id: AWS access/client id - access_key: AWS access/client id
### References ###
- *:discovery:*:*:1.0 (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] services to resolve connections - *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials
See Also
[[https://pip-services3-node.github.io/pip-services3-components-node/classes/connect.connectionparams.html ConnectionParams]] (in the Pip.Services components package)
[[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] (in the Pip.Services components package)
### Example ###
let config = ConfigParams.fromTuples( "connection.region", "us-east1", "connection.service", "s3", "connection.bucket", "mybucket", "credential.access_id", "XXXXXXXXXX", "credential.access_key", "XXXXXXXXXX" );
let connectionResolver = new AwsConnectionResolver(); connectionResolver.configure(config); connectionResolver.setReferences(references);
connectionResolver.resolve("123", (err, connection) => { // Now use connection... });
method configure
configure: (config: ConfigParams) => void;
Configures component by passing configuration parameters.
Parameter config
configuration parameters to be set.
method resolve
resolve: ( correlationId: string, callback: (err: any, connection: AwsConnectionParams) => void) => void;
Resolves connection and credental parameters and generates a single AWSConnectionParams value.
Parameter correlationId
(optional) transaction id to trace execution through call chain.
Parameter callback
callback function that receives AWSConnectionParams value or error.
See Also
[[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] (in the Pip.Services components package)
method setReferences
setReferences: (references: IReferences) => void;
Sets references to dependent components.
Parameter references
references to locate the component dependencies.
class CloudWatchCounters
class CloudWatchCounters extends CachedCounters implements IReferenceable, IOpenable {}
Performance counters that periodically dumps counters to AWS Cloud Watch Metrics.
### Configuration parameters ###
- connections: - discovery_key: (optional) a key to retrieve the connection from [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] - region: (optional) AWS region - credentials: - store_key: (optional) a key to retrieve the credentials from [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/auth.icredentialstore.html ICredentialStore]] - access_id: AWS access/client id - access_key: AWS access/client id - options: - interval: interval in milliseconds to save current counters measurements (default: 5 mins) - reset_timeout: timeout in milliseconds to reset the counters. 0 disables the reset (default: 0)
### References ###
- *:context-info:*:*:1.0 (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/classes/info.contextinfo.html ContextInfo]] to detect the context id and specify counters source - *:discovery:*:*:1.0 (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] services to resolve connections - *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials
See Also
[[https://pip-services3-node.github.io/pip-services3-components-node/classes/count.counter.html Counter]] (in the Pip.Services components package)
[[https://pip-services3-node.github.io/pip-services3-components-node/classes/count.cachedcounters.html CachedCounters]] (in the Pip.Services components package)
[[https://pip-services3-node.github.io/pip-services3-components-node/classes/log.compositelogger.html CompositeLogger]] (in the Pip.Services components package)
### Example ###
let counters = new CloudWatchCounters(); counters.config(ConfigParams.fromTuples( "connection.region", "us-east-1", "connection.access_id", "XXXXXXXXXXX", "connection.access_key", "XXXXXXXXXXX" )); counters.setReferences(References.fromTuples( new Descriptor("pip-services", "logger", "console", "default", "1.0"), new ConsoleLogger() ));
counters.open("123", (err) => { ... });
counters.increment("mycomponent.mymethod.calls"); let timing = counters.beginTiming("mycomponent.mymethod.exec_time"); try { ... } finally { timing.endTiming(); }
counters.dump();
constructor
constructor();
Creates a new instance of this counters.
method close
close: (correlationId: string, callback: (err: any) => void) => void;
Closes component and frees used resources.
Parameter correlationId
(optional) transaction id to trace execution through call chain.
Parameter callback
callback function that receives error or null no errors occured.
method configure
configure: (config: ConfigParams) => void;
Configures component by passing configuration parameters.
Parameter config
configuration parameters to be set.
method isOpen
isOpen: () => boolean;
Checks if the component is opened.
Returns
true if the component has been opened and false otherwise.
method open
open: (correlationId: string, callback: (err: any) => void) => void;
Opens the component.
Parameter correlationId
(optional) transaction id to trace execution through call chain.
Parameter callback
callback function that receives error or null no errors occured.
method save
protected save: (counters: Counter[]) => void;
Saves the current counters measurements.
Parameter counters
current counters measurements to be saves.
method setReferences
setReferences: (references: IReferences) => void;
Sets references to dependent components.
Parameter references
references to locate the component dependencies.
See Also
[[https://pip-services3-node.github.io/pip-services3-commons-node/interfaces/refer.ireferences.html IReferences]] (in the Pip.Services commons package)
class CloudWatchLogger
class CloudWatchLogger extends CachedLogger implements IReferenceable, IOpenable {}
Logger that writes log messages to AWS Cloud Watch Log.
### Configuration parameters ###
- stream: (optional) Cloud Watch Log stream (default: context name) - group: (optional) Cloud Watch Log group (default: context instance ID or hostname) - connections: - discovery_key: (optional) a key to retrieve the connection from [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] - region: (optional) AWS region - credentials: - store_key: (optional) a key to retrieve the credentials from [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/auth.icredentialstore.html ICredentialStore]] - access_id: AWS access/client id - access_key: AWS access/client id - options: - interval: interval in milliseconds to save current counters measurements (default: 5 mins) - reset_timeout: timeout in milliseconds to reset the counters. 0 disables the reset (default: 0)
### References ###
- *:context-info:*:*:1.0 (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/classes/info.contextinfo.html ContextInfo]] to detect the context id and specify counters source - *:discovery:*:*:1.0 (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] services to resolve connections - *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials
See Also
[[https://pip-services3-node.github.io/pip-services3-components-node/classes/count.counter.html Counter]] (in the Pip.Services components package)
[[https://pip-services3-node.github.io/pip-services3-components-node/classes/count.cachedcounters.html CachedCounters]] (in the Pip.Services components package)
[[https://pip-services3-node.github.io/pip-services3-components-node/classes/log.compositelogger.html CompositeLogger]] (in the Pip.Services components package)
### Example ###
let logger = new Logger(); logger.config(ConfigParams.fromTuples( "stream", "mystream", "group", "mygroup", "connection.region", "us-east-1", "connection.access_id", "XXXXXXXXXXX", "connection.access_key", "XXXXXXXXXXX" )); logger.setReferences(References.fromTuples( new Descriptor("pip-services", "logger", "console", "default", "1.0"), new ConsoleLogger() ));
logger.open("123", (err) => { ... });
logger.setLevel(LogLevel.debug);
logger.error("123", ex, "Error occured: %s", ex.message); logger.debug("123", "Everything is OK.");
constructor
constructor();
Creates a new instance of this logger.
method close
close: (correlationId: string, callback: (err: any) => void) => void;
Closes component and frees used resources.
Parameter correlationId
(optional) transaction id to trace execution through call chain.
Parameter callback
callback function that receives error or null no errors occured.
method configure
configure: (config: ConfigParams) => void;
Configures component by passing configuration parameters.
Parameter config
configuration parameters to be set.
method isOpen
isOpen: () => boolean;
Checks if the component is opened.
Returns
true if the component has been opened and false otherwise.
method open
open: (correlationId: string, callback: (err: any) => void) => void;
Opens the component.
Parameter correlationId
(optional) transaction id to trace execution through call chain.
Parameter callback
callback function that receives error or null no errors occured.
method save
protected save: (messages: LogMessage[], callback: (err: any) => void) => void;
Saves log messages from the cache.
Parameter messages
a list with log messages
Parameter callback
callback function that receives error or null for success.
method setReferences
setReferences: (references: IReferences) => void;
Sets references to dependent components.
Parameter references
references to locate the component dependencies.
See Also
[[https://pip-services3-node.github.io/pip-services3-commons-node/interfaces/refer.ireferences.html IReferences]] (in the Pip.Services commons package)
method write
protected write: ( level: LogLevel, correlationId: string, ex: Error, message: string) => void;
Writes a log message to the logger destination.
Parameter level
a log level.
Parameter correlationId
(optional) transaction id to trace execution through call chain.
Parameter error
an error object associated with this message.
Parameter message
a human-readable message to log.
class CloudWatchUnit
class CloudWatchUnit {}
Constants that determine cloud watch units.
property Bits
static readonly Bits: string;
property Bits_Second
static readonly Bits_Second: string;
property Bytes
static readonly Bytes: string;
property Bytes_Second
static readonly Bytes_Second: string;
property Count
static readonly Count: string;
property Count_Second
static readonly Count_Second: string;
property Gigabits
static readonly Gigabits: string;
property Gigabits_Second
static readonly Gigabits_Second: string;
property Gigabytes
static readonly Gigabytes: string;
property Gigabytes_Second
static readonly Gigabytes_Second: string;
property Kilobits
static readonly Kilobits: string;
property Kilobits_Second
static readonly Kilobits_Second: string;
property Kilobytes
static readonly Kilobytes: string;
property Kilobytes_Second
static readonly Kilobytes_Second: string;
property Megabits
static readonly Megabits: string;
property Megabits_Second
static readonly Megabits_Second: string;
property Megabytes
static readonly Megabytes: string;
property Megabytes_Second
static readonly Megabytes_Second: string;
property Microseconds
static readonly Microseconds: string;
property Milliseconds
static readonly Milliseconds: string;
property None
static readonly None: string;
property Percent
static readonly Percent: string;
property Seconds
static readonly Seconds: string;
property Terabits
static readonly Terabits: string;
property Terabits_Second
static readonly Terabits_Second: string;
property Terabytes
static readonly Terabytes: string;
property Terabytes_Second
static readonly Terabytes_Second: string;
class CommandableLambdaClient
class CommandableLambdaClient extends LambdaClient {}
Abstract client that calls commandable AWS Lambda Functions.
Commandable services are generated automatically for [[https://pip-services3-node.github.io/pip-services3-commons-node/interfaces/commands.icommandable.html 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 [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] - region: (optional) AWS region - credentials: - store_key: (optional) a key to retrieve the credentials from [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/auth.icredentialstore.html 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) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/log.ilogger.html ILogger]] components to pass log messages - *:counters:*:*:1.0 (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/count.icounters.html ICounters]] components to pass collected measurements - *:discovery:*:*:1.0 (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] services to resolve connection - *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials
See Also
[[LambdaFunction]]
### Example ###
class MyLambdaClient extends CommandableLambdaClient implements IMyClient { ...
public getData(correlationId: string, id: string, callback: (err: any, result: MyData) => void): void {
this.callCommand( "get_data", correlationId, { id: id }, (err, result) => { callback(err, result); } ); } ... }
let client = new MyLambdaClient(); client.configure(ConfigParams.fromTuples( "connection.region", "us-east-1", "connection.access_id", "XXXXXXXXXXX", "connection.access_key", "XXXXXXXXXXX", "connection.arn", "YYYYYYYYYYYYY" ));
client.getData("123", "1", (err, result) => { ... });
constructor
constructor(name: string);
Creates a new instance of this client.
Parameter name
a service name.
method callCommand
callCommand: ( cmd: string, correlationId: string, params: any, callback: (err: any, result: any) => void) => void;
Calls a remote action in AWS Lambda function. The name of the action is added as "cmd" parameter to the action parameters.
Parameter cmd
an action name
Parameter correlationId
(optional) transaction id to trace execution through call chain.
Parameter params
command parameters.
Parameter callback
callback function that receives result or error.
class CommandableLambdaFunction
abstract class CommandableLambdaFunction extends 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 [[https://pip-services3-node.github.io/pip-services3-commons-node/interfaces/commands.icommandable.html 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 [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] - region: (optional) AWS region - credentials: - store_key: (optional) a key to retrieve the credentials from [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/auth.icredentialstore.html ICredentialStore]] - access_id: AWS access/client id - access_key: AWS access/client id
### References ###
- *:logger:*:*:1.0 (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/log.ilogger.html ILogger]] components to pass log messages - *:counters:*:*:1.0 (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/count.icounters.html ICounters]] components to pass collected measurements - *:discovery:*:*:1.0 (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] services to resolve connection - *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials
See Also
[[LambdaClient]]
### Example ###
class MyLambdaFunction extends CommandableLambdaFunction { private _controller: IMyController; ... public constructor() { base("mygroup", "MyGroup lambda function"); this._dependencyResolver.put( "controller", new Descriptor("mygroup","controller","*","*","1.0") ); } }
let lambda = new MyLambdaFunction();
service.run((err) => { console.log("MyLambdaFunction is started"); });
constructor
constructor(name: string, description?: string);
Creates a new instance of this lambda function.
Parameter name
(optional) a container name (accessible via ContextInfo)
Parameter description
(optional) a container description (accessible via ContextInfo)
method register
register: () => void;
Registers all actions in this lambda function.
class DefaultAwsFactory
class DefaultAwsFactory extends Factory {}
Creates AWS components by their descriptors.
See Also
[[CloudWatchLogger]]
[[CloudWatchCounters]]
constructor
constructor();
Create a new instance of the factory.
property CloudWatchCountersDescriptor
static readonly CloudWatchCountersDescriptor: Descriptor;
property CloudWatchLoggerDescriptor
static readonly CloudWatchLoggerDescriptor: Descriptor;
property Descriptor
static readonly Descriptor: Descriptor;
class LambdaClient
abstract class LambdaClient implements IOpenable, IConfigurable, IReferenceable {}
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 [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] - region: (optional) AWS region - credentials: - store_key: (optional) a key to retrieve the credentials from [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/auth.icredentialstore.html 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) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/log.ilogger.html ILogger]] components to pass log messages - *:counters:*:*:1.0 (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/count.icounters.html ICounters]] components to pass collected measurements - *:discovery:*:*:1.0 (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] services to resolve connection - *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials
See Also
[[LambdaFunction]]
[[CommandableLambdaClient]]
### Example ###
class MyLambdaClient extends LambdaClient implements IMyClient { ...
public getData(correlationId: string, id: string, callback: (err: any, result: MyData) => void): void {
let timing = this.instrument(correlationId, 'myclient.get_data'); this.call("get_data" correlationId, { id: id }, (err, result) => { timing.endTiming(); callback(err, result); }); } ... }
let client = new MyLambdaClient(); client.configure(ConfigParams.fromTuples( "connection.region", "us-east-1", "connection.access_id", "XXXXXXXXXXX", "connection.access_key", "XXXXXXXXXXX", "connection.arn", "YYYYYYYYYYYYY" ));
client.getData("123", "1", (err, result) => { ... });
method call
protected call: ( cmd: string, correlationId: string, params?: any, callback?: (err: any, result: any) => void) => void;
Calls a AWS Lambda Function action.
Parameter cmd
an action name to be called.
Parameter correlationId
(optional) transaction id to trace execution through call chain.
Parameter params
(optional) action parameters.
Parameter callback
(optional) callback function that receives result object or error.
method callOneWay
protected callOneWay: ( cmd: string, correlationId: string, params?: any, callback?: (err: any) => void) => void;
Calls a AWS Lambda Function action asynchronously without waiting for response.
Parameter cmd
an action name to be called.
Parameter correlationId
(optional) transaction id to trace execution through call chain.
Parameter params
(optional) action parameters.
Parameter callback
(optional) callback function that receives error or null for success.
method close
close: (correlationId: string, callback?: (err?: any) => void) => void;
Closes component and frees used resources.
Parameter correlationId
(optional) transaction id to trace execution through call chain.
Parameter callback
callback function that receives error or null no errors occured.
method configure
configure: (config: ConfigParams) => void;
Configures component by passing configuration parameters.
Parameter config
configuration parameters to be set.
method instrument
protected instrument: (correlationId: string, name: string) => CounterTiming;
Adds instrumentation to log calls and measure call time. It returns a CounterTiming object that is used to end the time measurement.
Parameter correlationId
(optional) transaction id to trace execution through call chain.
Parameter name
a method name.
Returns
CounterTiming object to end the time measurement.
method invoke
protected invoke: ( invocationType: string, cmd: string, correlationId: string, args: any, callback?: (err: any, result: any) => void) => void;
Performs AWS Lambda Function invocation.
Parameter invocationType
an invocation type: "RequestResponse" or "Event"
Parameter cmd
an action name to be called.
Parameter correlationId
(optional) transaction id to trace execution through call chain.
Parameter args
action arguments
Parameter callback
callback function that receives action result or error.
method isOpen
isOpen: () => boolean;
Checks if the component is opened.
Returns
true if the component has been opened and false otherwise.
method open
open: (correlationId: string, callback: (err?: any) => void) => void;
Opens the component.
Parameter correlationId
(optional) transaction id to trace execution through call chain.
Parameter callback
callback function that receives error or null no errors occured.
method setReferences
setReferences: (references: IReferences) => void;
Sets references to dependent components.
Parameter references
references to locate the component dependencies.
class LambdaFunction
abstract class LambdaFunction extends Container {}
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 [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] - region: (optional) AWS region - credentials: - store_key: (optional) a key to retrieve the credentials from [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/auth.icredentialstore.html ICredentialStore]] - access_id: AWS access/client id - access_key: AWS access/client id
### References ###
- *:logger:*:*:1.0 (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/log.ilogger.html ILogger]] components to pass log messages - *:counters:*:*:1.0 (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/count.icounters.html ICounters]] components to pass collected measurements - *:discovery:*:*:1.0 (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] services to resolve connection - *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials
See Also
[[LambdaClient]]
### Example ###
class MyLambdaFunction extends LambdaFunction { private _controller: IMyController; ... public constructor() { base("mygroup", "MyGroup lambda function"); this._dependencyResolver.put( "controller", new Descriptor("mygroup","controller","*","*","1.0") ); }
public setReferences(references: IReferences): void { base.setReferences(references); this._controller = this._dependencyResolver.getRequired("controller"); }
public register(): void { registerAction("get_mydata", null, (params, callback) => { let correlationId = params.correlation_id; let id = params.id; this._controller.getMyData(correlationId, id, callback); }); ... } }
let lambda = new MyLambdaFunction();
service.run((err) => { console.log("MyLambdaFunction is started"); });
constructor
constructor(name?: string, description?: string);
Creates a new instance of this lambda function.
Parameter name
(optional) a container name (accessible via ContextInfo)
Parameter description
(optional) a container description (accessible via ContextInfo)
method act
act: (params: any, callback: (err: any, result: any) => void) => void;
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.
Parameter params
action parameters.
Parameter callback
callback function that receives action result or error.
method getHandler
getHandler: () => (event: any, context: any) => void;
Gets entry point into this lambda function.
Parameter event
an incoming event object with invocation parameters.
Parameter context
a context object with local references.
method instrument
protected instrument: (correlationId: string, name: string) => CounterTiming;
Adds instrumentation to log calls and measure call time. It returns a CounterTiming object that is used to end the time measurement.
Parameter correlationId
(optional) transaction id to trace execution through call chain.
Parameter name
a method name.
Returns
CounterTiming object to end the time measurement.
method register
protected abstract register: () => void;
Registers all actions in this lambda function.
This method is called by the service and must be overriden in child classes.
method registerAction
protected registerAction: ( cmd: string, schema: Schema, action: (params: any, callback: (err: any, result: any) => void) => void) => void;
Registers an action in this lambda function.
Parameter cmd
a action/command name.
Parameter schema
a validation schema to validate received parameters.
Parameter action
an action function that is called when action is invoked.
method run
run: (callback?: (err: any) => void) => void;
Runs this lambda function, loads container configuration, instantiate components and manage their lifecycle, makes this function ready to access action calls.
Parameter callback
callback function that receives error or null for success.
method setReferences
setReferences: (references: IReferences) => void;
Sets references to dependent components.
Parameter references
references to locate the component dependencies.
Package Files (11)
- obj/src/build/DefaultAwsFactory.d.ts
- obj/src/clients/CommandableLambdaClient.d.ts
- obj/src/clients/LambdaClient.d.ts
- obj/src/connect/AwsConnectionParams.d.ts
- obj/src/connect/AwsConnectionResolver.d.ts
- obj/src/container/CommandableLambdaFunction.d.ts
- obj/src/container/LambdaFunction.d.ts
- obj/src/count/CloudWatchCounters.d.ts
- obj/src/count/CloudWatchUnit.d.ts
- obj/src/index.d.ts
- obj/src/log/CloudWatchLogger.d.ts
Dependencies (4)
Dev Dependencies (8)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/pip-services3-aws-node
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/pip-services3-aws-node)
- HTML<a href="https://www.jsdocs.io/package/pip-services3-aws-node"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 5793 ms. - Missing or incorrect documentation? Open an issue for this package.