UNPKG

serverless-offline

Version:

Emulate AWS λ and API Gateway locally when developing your Serverless project

32 lines (27 loc) 1.05 kB
'use strict'; /* Mimicks the lambda context object http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html */ module.exports = function createLambdaContext(fun, cb) { const functionName = fun.name; const endTime = new Date().getTime() + (fun.timeout ? fun.timeout * 1000 : 6000); const done = typeof cb === 'function' ? cb : ((x, y) => x || y); return { /* Methods */ done, succeed: result => done(null, result), fail: error => done(error, null), getRemainingTimeInMillis: () => endTime - new Date().getTime(), /* Properties */ functionName, memoryLimitInMB: fun.memorySize, functionVersion: 'offline_functionVersion_for_' + functionName, invokedFunctionArn: 'offline_invokedFunctionArn_for_' + functionName, awsRequestId: 'offline_awsRequestId_' + Math.random().toString(10).slice(2), logGroupName: 'offline_logGroupName_for_' + functionName, logStreamName: 'offline_logStreamName_for_' + functionName, identity: {}, clientContext: {}, }; };