diff --git a/lib/run.js b/lib/run.js index a417233..9535197 100644 --- a/lib/run.js +++ b/lib/run.js @@ -16,6 +16,8 @@ module.exports = { if (purge) { utils.purgeCache(handlerFilePath); } + //set environment before requiring, as imported modules will be immediately + this.setEnvironmentVars(functionId); const module = require(handlerFilePath); const functionObjectPath = handler.slice(1); let func = module; @@ -44,6 +46,14 @@ module.exports = { }; }, + setEnvironmentVars(functionName) { + const providerEnvVars = this.serverless.service.provider.environment || {}; + const functionEnvVars = this.serverless.service.functions[functionName].environment || {}; + + Object.assign(process.env, providerEnvVars, functionEnvVars); + console.log('core', process.env.NODE_ENV); + }, + run(stats) { const functionName = this.options.function; @@ -80,6 +90,7 @@ module.exports = { const handler = this.loadHandler(stats, functionName, true); const event = this.getEvent(); const context = this.getContext(functionName); + handler( event, context,