@webda/aws
Version:
Webda AWS Services implementation
63 lines • 1.79 kB
JavaScript
import { Lambda } from "@aws-sdk/client-lambda";
import { Runner, RunnerParameters } from "@webda/async";
import { AWSServiceParameters } from "./aws-mixin.js";
/**
*
*/
class LambdaCallerParameters extends AWSServiceParameters(RunnerParameters) {
}
/**
* A service that calls a Lambda function and retrieve its result
*
* @WebdaModda
*/
class LambdaCaller extends Runner {
/**
* @inheritdoc
*/
launchAction(action, info) {
// events.Records[0].eventSource
// Use the AWSEvents framework
return this.execute({
command: "launch",
service: info.JOB_ORCHESTRATOR,
method: "runWebdaAsyncAction",
action,
args: [info],
// We also put the value in JOB_INFO for other type of runner
JOB_INFO: info
}, true);
}
/**
* @inheritdoc
*/
loadParameters(params) {
return new LambdaCallerParameters(params);
}
/**
* @inheritdoc
*/
resolve() {
super.resolve();
this.client = new Lambda(this.parameters);
return this;
}
/**
* Execute the Lambda function
* @param params for the call
* @param async wait for Lambda result
* @param arn function to call default to the one from configuration
* @returns
*/
async execute(params = {}, async = false, arn = this.parameters.arn) {
return JSON.parse((await this.client.invoke({
FunctionName: arn,
ClientContext: null,
InvocationType: async ? "Event" : "RequestResponse",
LogType: "None",
Payload: Buffer.from(JSON.stringify(params))
})).Payload.toString());
}
}
export { LambdaCaller };
//# sourceMappingURL=lambdacaller.js.map