Skip to content

Commit

Permalink
Fallback to timeout and memorySize from provider
Browse files Browse the repository at this point in the history
  • Loading branch information
dobrynin committed May 3, 2019
1 parent 3307aa0 commit f70da0b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 23 deletions.
18 changes: 0 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/createAuthScheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function createAuthScheme(

let done = false;
// Creat the Lambda Context for the Auth function
const lambdaContext = createLambdaContext(authFun, (err, result, fromPromise) => {
const lambdaContext = createLambdaContext(authFun, serverless.service.provider, (err, result, fromPromise) => {
if (done) {
const warning = fromPromise
? `Warning: Auth function '${authFunName}' returned a promise and also uses a callback!\nThis is problematic and might cause issues in your lambda.`
Expand Down
7 changes: 4 additions & 3 deletions src/createLambdaContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ const utils = require('./utils');
Mimicks the lambda context object
http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html
*/
module.exports = function createLambdaContext(fun, cb) {
module.exports = function createLambdaContext(fun, provider, cb) {

const functionName = fun.name;
const endTime = new Date().getTime() + (fun.timeout ? fun.timeout * 1000 : 6000);
const timeout = (fun.timeout ? fun.timeout : provider.timeout ? provider.timeout : 6) * 1000; // default 6 second timeout
const endTime = new Date().getTime() + timeout;
const done = typeof cb === 'function' ? cb : ((x, y) => x || y); // eslint-disable-line no-extra-parens

return {
Expand All @@ -19,7 +20,7 @@ module.exports = function createLambdaContext(fun, cb) {

/* Properties */
functionName,
memoryLimitInMB: fun.memorySize,
memoryLimitInMB: fun.memorySize || provider.memorySize,
functionVersion: `offline_functionVersion_for_${functionName}`,
invokedFunctionArn: `offline_invokedFunctionArn_for_${functionName}`,
awsRequestId: `offline_awsRequestId_${utils.randomId()}`,
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ class Offline {
debugLog('event:', event);

// We create the context, its callback (context.done/succeed/fail) will send the HTTP response
const lambdaContext = createLambdaContext(fun, (err, data, fromPromise) => {
const lambdaContext = createLambdaContext(fun, this.service.provider, (err, data, fromPromise) => {
// Everything in this block happens once the lambda function has resolved
debugLog('_____ HANDLER RESOLVED _____');

Expand Down

0 comments on commit f70da0b

Please sign in to comment.