UNPKG

simple-lambda-client

Version:

A simple, convenient way to invoke aws lambda functions with best practices.

48 lines 2.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.invokeLambdaFunction = void 0; const simple_in_memory_cache_1 = require("simple-in-memory-cache"); const with_simple_caching_1 = require("with-simple-caching"); const getSimpleLambdaClientCacheKey_1 = require("./cache/getSimpleLambdaClientCacheKey"); const executeLambdaInvocation_1 = require("./executeLambdaInvocation"); /** * create a global synchronous cache that can be used to dedupe parallel requests infront of the async cache * * note * - this is required because we are instantiating the wrapper on each call * - this is passed in as an input to the wrapper */ const globalSyncCache = (0, simple_in_memory_cache_1.createCache)({ expiration: { seconds: 15 }, // per instructions in with-simple-caching, this must be as long as the longest promise duration }); /** * a method to invoke a lambda function with best practices */ const invokeLambdaFunction = async ({ service: serviceName, function: functionName, stage, event, logDebug, cache, }) => { // define how to execute the lambda, based on whether caching was requested const execute = cache ? (0, with_simple_caching_1.withSimpleCachingAsync)(executeLambdaInvocation_1.executeLambdaInvocation, { cache: { output: cache, deduplication: globalSyncCache }, serialize: { key: ({ forInput: [input] }) => (0, getSimpleLambdaClientCacheKey_1.getSimpleLambdaClientCacheKey)({ service: input.serviceName, function: input.functionName, stage: input.stage, event: input.event, }), }, }) : executeLambdaInvocation_1.executeLambdaInvocation; // execute the lambda const result = await execute({ serviceName, stage, functionName, event, logDebug, }); // return the result return result; }; exports.invokeLambdaFunction = invokeLambdaFunction; //# sourceMappingURL=invokeLambdaFunction.js.map