@cumulus/aws-client
Version:
Utilities for working with AWS
45 lines • 1.5 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.invoke = exports.isEventBridgeEvent = void 0;
/**
* @module Lambda
*/
const client_lambda_1 = require("@aws-sdk/client-lambda");
const logger_1 = __importDefault(require("@cumulus/logger"));
const services_1 = require("./services");
const test_utils_1 = require("./test-utils");
const log = new logger_1.default({ sender: 'aws-client/Lambda' });
/**
* Bare check for EventBridge shape
*/
const isEventBridgeEvent = (event) => (event instanceof Object
&& 'detail' in event);
exports.isEventBridgeEvent = isEventBridgeEvent;
/**
* Invoke a Lambda function
*/
const invoke = async (name, payload, type = 'Event') => {
if (process.env.IS_LOCAL || (0, test_utils_1.inTestMode)()) {
log.info(`Faking Lambda invocation for ${name}`);
return undefined;
}
log.info(`Invoking ${name}`);
let response;
try {
response = await (0, services_1.lambda)().send(new client_lambda_1.InvokeCommand({
FunctionName: name,
Payload: new TextEncoder().encode(JSON.stringify(payload)),
InvocationType: type,
}));
}
catch (error) {
log.error(`Error invoking ${name}`, error);
throw error;
}
return response;
};
exports.invoke = invoke;
//# sourceMappingURL=Lambda.js.map
;