Skip to content

Commit 3e4cfed

Browse files
dantmanDeviaVir
authored andcommitted
Set environment variables before requiring module (#137)
In Lambda, the process.env variables are set at the very beginning before anything is run. `run` needs to set `process.env` before it requires the handler, otherwise the handler's script file or dependencies cannot do initialization using the env variables outside of the handler itself.
1 parent 302fdf7 commit 3e4cfed

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/main.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ Lambda.prototype.run = function (program) {
4242
var filename = splitHandler[0] + '.js';
4343
var handlername = splitHandler[1];
4444

45-
var handler = require(process.cwd() + '/' + filename)[handlername];
46-
var event = require(process.cwd() + '/' + program.eventFile);
47-
var context = require(process.cwd() + '/' + program.contextFile);
48-
4945
// Set custom environment variables if program.configFile is defined
5046
if (program.configFile) {
5147
this._setRunTimeEnvironmentVars(program);
5248
}
5349

50+
var handler = require(process.cwd() + '/' + filename)[handlername];
51+
var event = require(process.cwd() + '/' + program.eventFile);
52+
var context = require(process.cwd() + '/' + program.contextFile);
53+
5454
this._runHandler(handler, event, program.runtime, context);
5555
};
5656

0 commit comments

Comments
 (0)