UNPKG

7.49 kBTypeScriptView Raw
1import { IOpenable } from 'pip-services3-commons-node';
2import { IConfigurable } from 'pip-services3-commons-node';
3import { IReferenceable } from 'pip-services3-commons-node';
4import { IReferences } from 'pip-services3-commons-node';
5import { ConfigParams } from 'pip-services3-commons-node';
6import { DependencyResolver } from 'pip-services3-commons-node';
7import { CompositeLogger } from 'pip-services3-components-node';
8import { CompositeCounters } from 'pip-services3-components-node';
9import { CounterTiming } from 'pip-services3-components-node';
10import { AwsConnectionParams } from '../connect/AwsConnectionParams';
11import { AwsConnectionResolver } from '../connect/AwsConnectionResolver';
12/**
13 * Abstract client that calls AWS Lambda Functions.
14 *
15 * When making calls "cmd" parameter determines which what action shall be called, while
16 * other parameters are passed to the action itself.
17 *
18 * ### Configuration parameters ###
19 *
20 * - connections:
21 * - 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]]
22 * - region: (optional) AWS region
23 * - credentials:
24 * - 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]]
25 * - access_id: AWS access/client id
26 * - access_key: AWS access/client id
27 * - options:
28 * - connect_timeout: (optional) connection timeout in milliseconds (default: 10 sec)
29 *
30 * ### References ###
31 *
32 * - <code>\*:logger:\*:\*:1.0</code> (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/log.ilogger.html ILogger]] components to pass log messages
33 * - <code>\*:counters:\*:\*:1.0</code> (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/count.icounters.html ICounters]] components to pass collected measurements
34 * - <code>\*:discovery:\*:\*:1.0</code> (optional) [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]] services to resolve connection
35 * - <code>\*:credential-store:\*:\*:1.0</code> (optional) Credential stores to resolve credentials
36 *
37 * @see [[LambdaFunction]]
38 * @see [[CommandableLambdaClient]]
39 *
40 * ### Example ###
41 *
42 * class MyLambdaClient extends LambdaClient implements IMyClient {
43 * ...
44 *
45 * public getData(correlationId: string, id: string,
46 * callback: (err: any, result: MyData) => void): void {
47 *
48 * let timing = this.instrument(correlationId, 'myclient.get_data');
49 * this.call("get_data" correlationId, { id: id }, (err, result) => {
50 * timing.endTiming();
51 * callback(err, result);
52 * });
53 * }
54 * ...
55 * }
56 *
57 * let client = new MyLambdaClient();
58 * client.configure(ConfigParams.fromTuples(
59 * "connection.region", "us-east-1",
60 * "connection.access_id", "XXXXXXXXXXX",
61 * "connection.access_key", "XXXXXXXXXXX",
62 * "connection.arn", "YYYYYYYYYYYYY"
63 * ));
64 *
65 * client.getData("123", "1", (err, result) => {
66 * ...
67 * });
68 */
69export declare abstract class LambdaClient implements IOpenable, IConfigurable, IReferenceable {
70 /**
71 * The reference to AWS Lambda Function.
72 */
73 protected _lambda: any;
74 /**
75 * The opened flag.
76 */
77 protected _opened: boolean;
78 /**
79 * The AWS connection parameters
80 */
81 protected _connection: AwsConnectionParams;
82 private _connectTimeout;
83 /**
84 * The dependencies resolver.
85 */
86 protected _dependencyResolver: DependencyResolver;
87 /**
88 * The connection resolver.
89 */
90 protected _connectionResolver: AwsConnectionResolver;
91 /**
92 * The logger.
93 */
94 protected _logger: CompositeLogger;
95 /**
96 * The performance counters.
97 */
98 protected _counters: CompositeCounters;
99 /**
100 * Configures component by passing configuration parameters.
101 *
102 * @param config configuration parameters to be set.
103 */
104 configure(config: ConfigParams): void;
105 /**
106 * Sets references to dependent components.
107 *
108 * @param references references to locate the component dependencies.
109 */
110 setReferences(references: IReferences): void;
111 /**
112 * Adds instrumentation to log calls and measure call time.
113 * It returns a CounterTiming object that is used to end the time measurement.
114 *
115 * @param correlationId (optional) transaction id to trace execution through call chain.
116 * @param name a method name.
117 * @returns CounterTiming object to end the time measurement.
118 */
119 protected instrument(correlationId: string, name: string): CounterTiming;
120 /**
121 * Checks if the component is opened.
122 *
123 * @returns true if the component has been opened and false otherwise.
124 */
125 isOpen(): boolean;
126 /**
127 * Opens the component.
128 *
129 * @param correlationId (optional) transaction id to trace execution through call chain.
130 * @param callback callback function that receives error or null no errors occured.
131 */
132 open(correlationId: string, callback: (err?: any) => void): void;
133 /**
134 * Closes component and frees used resources.
135 *
136 * @param correlationId (optional) transaction id to trace execution through call chain.
137 * @param callback callback function that receives error or null no errors occured.
138 */
139 close(correlationId: string, callback?: (err?: any) => void): void;
140 /**
141 * Performs AWS Lambda Function invocation.
142 *
143 * @param invocationType an invocation type: "RequestResponse" or "Event"
144 * @param cmd an action name to be called.
145 * @param correlationId (optional) transaction id to trace execution through call chain.
146 * @param args action arguments
147 * @param callback callback function that receives action result or error.
148 */
149 protected invoke(invocationType: string, cmd: string, correlationId: string, args: any, callback?: (err: any, result: any) => void): void;
150 /**
151 * Calls a AWS Lambda Function action.
152 *
153 * @param cmd an action name to be called.
154 * @param correlationId (optional) transaction id to trace execution through call chain.
155 * @param params (optional) action parameters.
156 * @param callback (optional) callback function that receives result object or error.
157 */
158 protected call(cmd: string, correlationId: string, params?: any, callback?: (err: any, result: any) => void): void;
159 /**
160 * Calls a AWS Lambda Function action asynchronously without waiting for response.
161 *
162 * @param cmd an action name to be called.
163 * @param correlationId (optional) transaction id to trace execution through call chain.
164 * @param params (optional) action parameters.
165 * @param callback (optional) callback function that receives error or null for success.
166 */
167 protected callOneWay(cmd: string, correlationId: string, params?: any, callback?: (err: any) => void): void;
168}